diff options
| author | Jokler <jokler.contact@gmail.com> | 2018-01-04 19:12:01 +0100 |
|---|---|---|
| committer | Jokler <jokler.contact@gmail.com> | 2018-01-04 19:12:01 +0100 |
| commit | 37056a823a574add2cd452a97f328bb170400a0b (patch) | |
| tree | 0b7851f09eb003b532e533e715e72e8df6f809fe /src | |
| parent | 32e870aeefee587d6eabdfa08cf27b3cf9a46f15 (diff) | |
| download | frippy-37056a823a574add2cd452a97f328bb170400a0b.tar.gz frippy-37056a823a574add2cd452a97f328bb170400a0b.zip | |
Return the future on connect instead of adding it to the reactor
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -108,11 +108,12 @@ impl Bot { self.plugins.remove(name) } - /// This connects the `Bot` to IRC and adds a task - /// to the Core that was supplied. + /// This connects the `Bot` to IRC and returns a `Future` + /// which represents the bots work. + /// This `Future` will run forever unless it returns an error. /// - /// You need to run the core, so that frippy - /// can do its work. + /// You need to run the `Future`, so that the `Bot` + /// can actually do its work. /// /// # Examples /// ```no_run @@ -128,11 +129,11 @@ impl Bot { /// let mut reactor = Core::new().unwrap(); /// let mut bot = Bot::new(); /// - /// bot.connect(&mut reactor, &config); - /// reactor.run(future::empty::<(), ()>()).unwrap(); + /// let future = bot.connect(&mut reactor, &config); + /// reactor.run(future).unwrap(); /// # } /// ``` - pub fn connect(&self, reactor: &mut Core, config: &Config) -> Option<()> { + pub fn connect(&self, reactor: &mut Core, config: &Config) -> Option<Box<futures::Future<Item = (), Error = ()>>> { info!("Plugins loaded: {}", self.plugins); let server = @@ -157,13 +158,12 @@ impl Bot { // TODO Verify if we actually need to clone plugins twice let plugins = self.plugins.clone(); - let task = server + let future = server .stream() .for_each(move |message| process_msg(&server, plugins.clone(), message)) .map_err(|e| error!("Failed to process message: {}", e)); - reactor.handle().spawn(task); - Some(()) + Some(Box::new(future)) } } |
