diff options
| author | Austin Hellyer <[email protected]> | 2016-11-19 15:14:06 -0800 |
|---|---|---|
| committer | Austin Hellyer <[email protected]> | 2016-11-19 15:14:06 -0800 |
| commit | 87f03ea4384cf3293558171c56257d03dbb6766c (patch) | |
| tree | 4a70c3e2c168433344f8590f403a7167667d3b4e /src/client/dispatch.rs | |
| parent | Fix cond. compile across multiple feature targets (diff) | |
| download | serenity-87f03ea4384cf3293558171c56257d03dbb6766c.tar.xz serenity-87f03ea4384cf3293558171c56257d03dbb6766c.zip | |
Nonblocking connection
The connection is now non-blocking, allowing user event handlers to
immediately unlock it themselves (assuming they haven't unlocked it
elsewhere), rather than waiting on the library to receive an event.
This is done by decoupling the receiver away from the connection,
which is not necessarily "directly" associated with the connection.
This needs a _lot_ of code cleanup later.
Diffstat (limited to 'src/client/dispatch.rs')
| -rw-r--r-- | src/client/dispatch.rs | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs index 8798723..80b2061 100644 --- a/src/client/dispatch.rs +++ b/src/client/dispatch.rs @@ -3,7 +3,6 @@ use std::thread; use super::event_store::EventStore; use super::login_type::LoginType; use super::{Connection, Context}; -use ::internal::prelude::*; use ::model::{ChannelId, Event, Message}; #[cfg(feature="framework")] @@ -42,13 +41,13 @@ fn context(channel_id: Option<ChannelId>, } #[cfg(feature="framework")] -pub fn dispatch(event: Result<Event>, +pub fn dispatch(event: Event, conn: Arc<Mutex<Connection>>, framework: Arc<Mutex<Framework>>, login_type: LoginType, event_store: Arc<Mutex<EventStore>>) { match event { - Ok(Event::MessageCreate(event)) => { + Event::MessageCreate(event) => { let context = context(Some(event.message.channel_id), conn, login_type); @@ -64,8 +63,7 @@ pub fn dispatch(event: Result<Event>, dispatch_message(context, event.message, event_store); } }, - Ok(other) => handle_event(other, conn, login_type, event_store), - Err(_why) => {}, + other => handle_event(other, conn, login_type, event_store), } } @@ -75,7 +73,7 @@ pub fn dispatch(event: Result<Event>, login_type: LoginType, event_store: Arc<Mutex<EventStore>>) { match event { - Ok(Event::MessageCreate(event)) => { + Event::MessageCreate(event) => { let context = context(Some(event.message.channel_id), conn, login_type); @@ -83,8 +81,7 @@ pub fn dispatch(event: Result<Event>, event.message.clone(), event_store); }, - Ok(other) => handle_event(other, conn, login_type, event_store), - Err(_why) => {}, + other => handle_event(other, conn, login_type, event_store), } } |