aboutsummaryrefslogtreecommitdiff
path: root/src/client/dispatch.rs
diff options
context:
space:
mode:
authorMishio595 <[email protected]>2018-11-13 22:23:39 -0700
committerMishio595 <[email protected]>2018-11-13 22:23:39 -0700
commit1dad6996d8e9c983dc9e1689a93dbef5b0696c22 (patch)
tree1ee7226178cae76b20e6adcdc7e7cfcc3c477c32 /src/client/dispatch.rs
parentFinish rebase (diff)
parentMake `Region`s `Japan`-variant lowercase. (diff)
downloadserenity-1dad6996d8e9c983dc9e1689a93dbef5b0696c22.tar.xz
serenity-1dad6996d8e9c983dc9e1689a93dbef5b0696c22.zip
Merge branch 'upstream'
Diffstat (limited to 'src/client/dispatch.rs')
-rw-r--r--src/client/dispatch.rs31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs
index e201852..2c8dd61 100644
--- a/src/client/dispatch.rs
+++ b/src/client/dispatch.rs
@@ -25,20 +25,31 @@ use std::time::Duration;
#[cfg(feature = "cache")]
use super::CACHE;
+#[cfg(feature = "cache")]
+lazy_static! {
+ pub static ref CACHE_TRY_WRITE_DURATION: Option<Duration> =
+ CACHE.read().get_try_write_duration();
+}
+
macro_rules! update {
($event:expr) => {
{
#[cfg(feature = "cache")]
{
- if let Some(mut lock) = CACHE.try_write_for(Duration::from_millis(10)) {
- lock.update(&mut $event)
- } else {
- warn!(
- "[dispatch] Possible deadlock: couldn't unlock cache to update with event: {:?}",
- $event,
- );
-
- None
+ match *CACHE_TRY_WRITE_DURATION {
+ Some(duration) => {
+ if let Some(mut lock) = CACHE.try_write_for(duration) {
+ lock.update(&mut $event)
+ } else {
+ warn!(
+ "[dispatch] Possible deadlock: couldn't unlock cache to update with event: {:?}",
+ $event,
+ );
+ None
+ }},
+ None => {
+ CACHE.write().update(&mut $event)
+ },
}
}
}
@@ -167,7 +178,7 @@ fn handle_event<H: EventHandler + Send + Sync + 'static>(
let context = context(data, runner_tx, shard_id);
// Discord sends both a MessageCreate and a ChannelCreate upon a new message in a private channel.
- // This could potentionally be annoying to handle when otherwise wanting to normally take care of a new channel.
+ // This could potentially be annoying to handle when otherwise wanting to normally take care of a new channel.
// So therefore, private channels are dispatched to their own handler code.
match event.channel {
Channel::Private(channel) => {