mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
echo_bot: unify send()
This commit is contained in:
parent
32031a239e
commit
d5768c4c78
1 changed files with 12 additions and 15 deletions
|
@ -14,19 +14,22 @@ fn main() {
|
||||||
|
|
||||||
let (sink, stream) = client.split();
|
let (sink, stream) = client.split();
|
||||||
let mut sink = Some(sink);
|
let mut sink = Some(sink);
|
||||||
let done = stream.for_each(move |event| {
|
let mut send = move |stanza| {
|
||||||
|
sink = Some(
|
||||||
|
sink.take().
|
||||||
|
expect("sink")
|
||||||
|
.send(stanza)
|
||||||
|
.wait()
|
||||||
|
.expect("sink.send")
|
||||||
|
);
|
||||||
|
};
|
||||||
|
let done = stream.for_each(|event| {
|
||||||
let result: Box<Future<Item=(), Error=String>> = match event {
|
let result: Box<Future<Item=(), Error=String>> = match event {
|
||||||
ClientEvent::Online => {
|
ClientEvent::Online => {
|
||||||
println!("Online!");
|
println!("Online!");
|
||||||
|
|
||||||
let presence = make_presence();
|
let presence = make_presence();
|
||||||
sink = Some(
|
send(presence);
|
||||||
sink.take().
|
|
||||||
expect("sink")
|
|
||||||
.send(presence)
|
|
||||||
.wait()
|
|
||||||
.expect("sink.send")
|
|
||||||
);
|
|
||||||
Box::new(
|
Box::new(
|
||||||
future::ok(())
|
future::ok(())
|
||||||
)
|
)
|
||||||
|
@ -42,13 +45,7 @@ fn main() {
|
||||||
match (from.as_ref(), body) {
|
match (from.as_ref(), body) {
|
||||||
(Some(from), Some(body)) => {
|
(Some(from), Some(body)) => {
|
||||||
let reply = make_reply(from, body);
|
let reply = make_reply(from, body);
|
||||||
sink = Some(
|
send(reply);
|
||||||
sink.take().
|
|
||||||
expect("sink")
|
|
||||||
.send(reply)
|
|
||||||
.wait()
|
|
||||||
.expect("sink.send")
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue