diff options
| author | Zeyla Hellyer <[email protected]> | 2018-01-21 09:28:05 -0800 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2018-01-21 09:29:44 -0800 |
| commit | 5138193c001b8d99f707dffb254b71ce8cefa182 (patch) | |
| tree | b5fbd11a55bb9f763a65cdedbebd0141dfe26fa6 | |
| parent | Bump to 0.4.7 (diff) | |
| download | serenity-5138193c001b8d99f707dffb254b71ce8cefa182.tar.xz serenity-5138193c001b8d99f707dffb254b71ce8cefa182.zip | |
Execute framework commands in a ThreadPool
The v0.5.x branch threadpools commands and events in the same pool, but
this isn't possible in the v0.4.x branch due to backwards compatibility.
To resolve this, create a second threadpool for just the framework.
Closes #250.
| -rw-r--r-- | src/framework/standard/mod.rs | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/src/framework/standard/mod.rs b/src/framework/standard/mod.rs index a806817..0ea38cf 100644 --- a/src/framework/standard/mod.rs +++ b/src/framework/standard/mod.rs @@ -22,6 +22,7 @@ use std::default::Default; use std::sync::Arc; use client::Context; use super::Framework; +use threadpool::ThreadPool; use model::{ChannelId, GuildId, Guild, Member, Message, UserId}; use model::permissions::Permissions; use internal::RwLockExt; @@ -195,6 +196,7 @@ pub struct StandardFramework { /// ../client/event_handler/trait.EventHandler.html#method.on_message /// [`Event::MessageCreate`]: ../model/event/enum.Event.html#variant.MessageCreate pub initialized: bool, + threadpool: ThreadPool, user_info: (u64, bool), } @@ -933,27 +935,29 @@ impl Framework for StandardFramework { return; } - if let Some(before) = before { - if !(before)(&mut context, &message, &built) { - return; + self.threadpool.execute(move || { + if let Some(before) = before { + if !(before)(&mut context, &message, &built) { + return; + } } - } - let result = match command.exec { - CommandType::StringResponse(ref x) => { - let _ = message.channel_id.say(x); + let result = match command.exec { + CommandType::StringResponse(ref x) => { + let _ = message.channel_id.say(x); - Ok(()) - }, - CommandType::Basic(ref x) => (x)(&mut context, &message, args), - CommandType::WithCommands(ref x) => { - (x)(&mut context, &message, groups, args) - }, - }; + Ok(()) + }, + CommandType::Basic(ref x) => (x)(&mut context, &message, args), + CommandType::WithCommands(ref x) => { + (x)(&mut context, &message, groups, args) + }, + }; - if let Some(after) = after { - (after)(&mut context, &message, &built, result); - } + if let Some(after) = after { + (after)(&mut context, &message, &built, result); + } + }); return; } |