aatxe / irc

the irc crate – usable, async IRC for Rust
Mozilla Public License 2.0
528 stars 97 forks source link

re-use existing Core? #139

Closed freddyb closed 6 years ago

freddyb commented 6 years ago

I'm writing an irc bot that's supposed to spawn multiple client connections, i.e., multiple IrcReactors. Hence, I'd like to reuse a tokio::Core.

I'm happy to implement this in a pull request, but what's the preferred way:

Should I just make the fields inner and handle inIrcReactor` public and create it like so

let myreactor =  IrcReactor { ... }

or should I rewrite IrcReactor::new() to optionally take a core parameter?

freddyb commented 6 years ago

looking at https://github.com/aatxe/irc/blob/develop/src/client/reactor.rs#L42-L54

aatxe commented 6 years ago

I'm not quite sure I follow. IrcReactor is just a (thin) wrapper of tokio::Core already. If you just want to run connections to multiple servers on one IrcReactor (i.e. one tokio::Core), you can use prepare_and_connect_server (or prepare and connect separately) and register_client_with_handler for each connection you want on that reactor. You can see this pattern in the multiserver example.

If I'm misunderstanding what you mean, can you maybe elaborate a bit more with some pseudocode of the code you'd like to write?

freddyb commented 6 years ago

Ah, that makes sense. Nevermind. :roll_eyes:

aatxe commented 6 years ago

For some historical context: my original motivation in writing IrcReactor was that people kept telling me they were interested in using the async support, but "afraid of tokio." The library internals (mostly the transport) are actually where all of the "tricky parts" lie, and having IrcReactor seemed to help get people over the psychological hurdle.