diff options
| author | Jokler <jokler.contact@gmail.com> | 2018-03-21 16:03:15 +0100 |
|---|---|---|
| committer | Jokler <jokler.contact@gmail.com> | 2018-03-21 16:03:54 +0100 |
| commit | 48f547826edd9db9b94376f240a785d8a19a993d (patch) | |
| tree | 8639d38c16d3e6e0f356d1c2f2b3c76bbe3dcc04 /src | |
| parent | ad14a3807eef4faa0690c269646142e24934afd0 (diff) | |
| download | frippy-48f547826edd9db9b94376f240a785d8a19a993d.tar.gz frippy-48f547826edd9db9b94376f240a785d8a19a993d.zip | |
Give names to any threads which are spawned
Diffstat (limited to 'src')
| -rw-r--r-- | src/error.rs | 4 | ||||
| -rw-r--r-- | src/lib.rs | 33 |
2 files changed, 26 insertions, 11 deletions
diff --git a/src/error.rs b/src/error.rs index 36d5724..ce56a04 100644 --- a/src/error.rs +++ b/src/error.rs @@ -17,6 +17,10 @@ pub enum ErrorKind { #[fail(display = "A connection error occured")] Connection, + /// Thread spawn error + #[fail(display = "Failed to spawn thread")] + ThreadSpawn, + /// A Url error #[fail(display = "A Url error has occured")] Url, @@ -61,7 +61,7 @@ pub mod error; use std::collections::HashMap; use std::fmt; -use std::thread::spawn; +use std::thread; use std::sync::Arc; pub use irc::client::prelude::*; @@ -229,6 +229,8 @@ impl ThreadedPlugins { self.plugins.remove(&name.to_lowercase()).map(|_| ()) } + /// Runs the execute functions on all plugins. + /// Any errors that occur are printed right away. pub fn execute_plugins(&mut self, client: &IrcClient, message: Message) { let message = Arc::new(message); @@ -250,11 +252,17 @@ impl ThreadedPlugins { let client = client.clone(); // Execute the plugin in another thread - spawn(move || { - if let Err(e) = plugin.execute_threaded(&client, &message) { - log_error(e); - }; - }); + if let Err(e) = thread::Builder::new() + .name(name) + .spawn(move || { + if let Err(e) = plugin.execute_threaded(&client, &message) { + log_error(e); + }; + }) + .context(ErrorKind::ThreadSpawn) + { + log_error(e.into()); + } } } } @@ -275,11 +283,14 @@ impl ThreadedPlugins { // Clone for the move - the client uses an Arc internally let client = client.clone(); let plugin = Arc::clone(plugin); - spawn(move || { - if let Err(e) = plugin.command(&client, command) { - log_error(e); - }; - }); + thread::Builder::new() + .name(name) + .spawn(move || { + if let Err(e) = plugin.command(&client, command) { + log_error(e); + }; + }) + .context(ErrorKind::ThreadSpawn)?; } Ok(()) |
