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]

[src]

Creates a new reactor.

[src]

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)
});

[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)
    })
});

[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)
});

[src]

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(())
})

[src]

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.

[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.

[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)