Struct irc::client::reactor::IrcReactor
[−]
[src]
pub struct IrcReactor { /* fields omitted */ }
A thin wrapper over an event loop.
An IRC reactor is used to create new IRC clients and to drive the management of all connected clients as the application runs. It can be used to run multiple clients on the same thread, as well as to get better control over error management in an IRC client.
For a full example usage, see irc::client::reactor
.
Methods
impl IrcReactor
[src]
fn new() -> Result<IrcReactor>
[src]
Creates a new reactor.
fn prepare_client<'a>(
&mut self,
config: &'a Config
) -> Result<IrcClientFuture<'a>>
[src]
&mut self,
config: &'a Config
) -> Result<IrcClientFuture<'a>>
Creates a representation of an IRC client that has not yet attempted to connect. In
particular, this representation is as a Future
that when run will produce a connected
IrcClient
.
Example
let future_client = IrcReactor::new().and_then(|mut reactor| { reactor.prepare_client(&config) });
fn connect_client(&mut self, future: IrcClientFuture) -> Result<IrcClient>
[src]
Runs an IrcClientFuture
, such as one from
prepare_client
to completion, yielding an IrcClient
.
Example
let client = IrcReactor::new().and_then(|mut reactor| { reactor.prepare_client(&config).and_then(|future| { reactor.connect_client(future) }) });
fn prepare_client_and_connect(&mut self, config: &Config) -> Result<IrcClient>
[src]
Creates a new IrcClient
from the specified configuration,
connecting immediately. This is guaranteed to be the composition of prepare_client
and
connect_client
.
Example
let client = IrcReactor::new().and_then(|mut reactor| { reactor.prepare_client_and_connect(&config) });
fn register_client_with_handler<F, U>(&mut self, client: IrcClient, handler: F) where
F: Fn(&IrcClient, Message) -> U + 'static,
U: IntoFuture<Item = (), Error = IrcError> + 'static,
[src]
F: Fn(&IrcClient, Message) -> U + 'static,
U: IntoFuture<Item = (), Error = IrcError> + 'static,
Registers the given client with the specified message handler. The reactor will store this
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.
Example
let mut reactor = IrcReactor::new().unwrap(); let client = reactor.prepare_client_and_connect(&config).unwrap(); reactor.register_client_with_handler(client, |client, msg| { // Message processing happens here. Ok(()) })
fn register_future<F>(&mut self, future: F) where
F: IntoFuture<Item = (), Error = IrcError> + 'static,
[src]
F: IntoFuture<Item = (), Error = IrcError> + 'static,
Registers an arbitrary future with this reactor. This is a sort of escape hatch that allows
you to take more control over what runs on the reactor without requiring you to bring in
additional knowledge about tokio
. It is suspected that register_client_with_handler
will
be sufficient for most use cases.
fn inner_handle(&self) -> Handle
[src]
Returns a handle to the internal event loop. This is a sort of escape hatch that allows you
to take more control over what runs on the reactor using tokio
. This can be used for
sharing this reactor with some elements of other libraries.
fn run(&mut self) -> Result<()>
[src]
Consumes all registered handlers and futures, and runs them. When using
register_client_with_handler
, this will block indefinitely (until failure occurs) as it
will simply continue to process new, incoming messages for each client that was registered.
Example
let mut reactor = IrcReactor::new().unwrap(); let client = reactor.prepare_client_and_connect(&config).unwrap(); reactor.register_client_with_handler(client, process_msg)