client: stream.poll_complete() for ease of use

This commit is contained in:
Astro 2017-08-24 20:10:58 +02:00
commit 58b5a84391
4 changed files with 24 additions and 20 deletions

View file

@ -10,7 +10,7 @@ use std::env::args;
use std::process::exit;
use try_from::TryFrom;
use tokio_core::reactor::Core;
use futures::{Future, Stream, Sink, future};
use futures::{Stream, Sink, future};
use tokio_xmpp::Client;
use minidom::Element;
use xmpp_parsers::presence::{Presence, Type as PresenceType, Show as PresenceShow};
@ -33,18 +33,11 @@ fn main() {
// Make the two interfaces for sending and receiving independent
// of each other so we can move one into a closure.
let (sink, stream) = client.split();
let (mut sink, stream) = client.split();
// Wrap sink in Option so that we can take() it for the send(self)
// to consume and return it back when ready.
let mut sink = Some(sink);
let mut send = move |stanza| {
sink = Some(
sink.take().
expect("sink")
.send(stanza)
.wait()
.expect("sink.send")
);
sink.start_send(stanza).expect("start_send");
};
// Main loop, processes events
let done = stream.for_each(|event| {