From ff9eba272254a474da7db80f3649b06398013105 Mon Sep 17 00:00:00 2001 From: Aaron Weiss Date: Sat, 27 Jan 2018 15:35:44 +0100 Subject: [PATCH] Made some of the reactor API more generic. --- src/client/reactor.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/client/reactor.rs b/src/client/reactor.rs index 54d75d2..c5875c9 100644 --- a/src/client/reactor.rs +++ b/src/client/reactor.rs @@ -1,6 +1,6 @@ //! A system for creating and managing IRC server connections. -use futures::{Future, Stream}; +use futures::{Future, IntoFuture, Stream}; use futures::future; use tokio_core::reactor::{Core, Handle}; @@ -46,9 +46,10 @@ impl IrcReactor { /// setup until the next call to run, where it will be used to process new messages over the /// connection indefinitely (or until failure). As registration is consumed by `run`, subsequent /// calls to run will require new registration. - pub fn register_server_with_handler( + pub fn register_server_with_handler( &mut self, server: IrcServer, handler: F - ) where F: Fn(&IrcServer, Message) -> error::Result<()> + 'static { + ) where F: Fn(&IrcServer, Message) -> U + 'static, + U: IntoFuture + 'static { self.handlers.push(Box::new(server.stream().for_each(move |message| { handler(&server, message) }))); @@ -60,8 +61,8 @@ impl IrcReactor { /// be sufficient for most use cases. pub fn register_future( &mut self, future: F - ) where F: Future + 'static { - self.handlers.push(Box::new(future)) + ) where F: IntoFuture + 'static { + self.handlers.push(Box::new(future.into_future())) } /// Returns a handle to the internal event loop. This is a sort of escape hatch that allows you