aboutsummaryrefslogtreecommitdiff
path: root/src/framework/standard
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-11-13 13:28:08 -0800
committerZeyla Hellyer <[email protected]>2017-11-13 13:29:03 -0800
commitf2c21ef5b15ef1f345cdc30f4b793e55905f15f4 (patch)
tree33a0d5e68976a31d750cefaf78df8b2577b63578 /src/framework/standard
parentFix strange behaviour when the prefix has spaces (#215) (diff)
downloadserenity-f2c21ef5b15ef1f345cdc30f4b793e55905f15f4.tar.xz
serenity-f2c21ef5b15ef1f345cdc30f4b793e55905f15f4.zip
Use the threadpool for framework command execution
Instead of executing framework commands in the shard runner thread (potentially blocking the shard runner from reading new messages over the websocket and heartbeating), dispatch framework commands to the shard runner's threadpool.
Diffstat (limited to 'src/framework/standard')
-rw-r--r--src/framework/standard/mod.rs44
1 files changed, 26 insertions, 18 deletions
diff --git a/src/framework/standard/mod.rs b/src/framework/standard/mod.rs
index 12ad797..dd7aaae 100644
--- a/src/framework/standard/mod.rs
+++ b/src/framework/standard/mod.rs
@@ -25,6 +25,7 @@ use std::collections::HashMap;
use std::default::Default;
use std::sync::Arc;
use super::Framework;
+use threadpool::ThreadPool;
#[cfg(feature = "cache")]
use client::CACHE;
@@ -836,7 +837,12 @@ impl StandardFramework {
}
impl Framework for StandardFramework {
- fn dispatch(&mut self, mut context: Context, message: Message) {
+ fn dispatch(
+ &mut self,
+ mut context: Context,
+ message: Message,
+ threadpool: &ThreadPool,
+ ) {
let res = command::positions(&mut context, &message, &self.configuration);
let positions = match res {
@@ -926,27 +932,29 @@ impl Framework for StandardFramework {
return;
}
- if let Some(before) = before {
- if !(before)(&mut context, &message, &built) {
- return;
+ 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;
}