diff options
| -rw-r--r-- | bin/main.rs | 9 | ||||
| -rw-r--r-- | src/lib.rs | 10 |
2 files changed, 13 insertions, 6 deletions
diff --git a/bin/main.rs b/bin/main.rs index 420e016..c9749b6 100644 --- a/bin/main.rs +++ b/bin/main.rs @@ -78,6 +78,7 @@ fn main() { // Create an event loop to run the connections on. let mut reactor = Core::new().unwrap(); + let mut task = false; // Open a connection and add work for each config for config in configs { @@ -104,9 +105,11 @@ fn main() { } } - bot.connect(&mut reactor, &config); + bot.connect(&mut reactor, &config).map(|_| task = true); } - // Run the main loop forever - reactor.run(future::empty::<(), ()>()).unwrap(); + if task { + // Run the main loop forever + reactor.run(future::empty::<(), ()>()).unwrap(); + } } @@ -132,7 +132,7 @@ impl Bot { /// reactor.run(future::empty::<(), ()>()).unwrap(); /// # } /// ``` - pub fn connect(&self, reactor: &mut Core, config: &Config) { + pub fn connect(&self, reactor: &mut Core, config: &Config) -> Option<()> { info!("Plugins loaded: {}", self.plugins); let server = @@ -140,7 +140,7 @@ impl Bot { Ok(v) => v, Err(e) => { error!("Failed to connect: {}", e); - return; + return None; } }; @@ -148,7 +148,10 @@ impl Bot { match server.identify() { Ok(_) => info!("Identified"), - Err(e) => error!("Failed to identify: {}", e), + Err(e) => { + error!("Failed to identify: {}", e); + return None; + } }; // TODO Verify if we actually need to clone plugins twice @@ -160,6 +163,7 @@ impl Bot { .map_err(|e| error!("Failed to process message: {}", e)); reactor.handle().spawn(task); + Some(()) } } |
