@@ -6,6 +6,8 @@ use async_trait::async_trait;
66use strum:: { EnumCount , IntoStaticStr , VariantNames } ;
77
88use super :: context:: Context ;
9+ #[ cfg( doc) ]
10+ use crate :: gateway:: ShardRunner ;
911use crate :: gateway:: ShardStageUpdateEvent ;
1012use crate :: http:: RatelimitInfo ;
1113use crate :: model:: prelude:: * ;
@@ -19,12 +21,8 @@ pub trait EventHandler: Send + Sync {
1921 ///
2022 /// ## Warning
2123 ///
22- /// This will run synchronously on every event in the dispatch loop
23- /// of the shard that is receiving the event. If your filter code
24- /// takes too long, it may delay other events from being dispatched
25- /// in a timely manner. It is recommended to keep the runtime
26- /// complexity of the filter code low to avoid unnecessarily blocking
27- /// your bot.
24+ /// Similar to [`RawEventHandler`], this method runs synchronously to the [`ShardRunner`], keep
25+ /// runtime complexity low.
2826 fn filter_event ( & self , _context : & Context , _event : & Event ) -> bool {
2927 true
3028 }
@@ -415,7 +413,17 @@ full_event! {
415413 MessagePollVoteRemove { event: MessagePollVoteRemoveEvent } ;
416414}
417415
418- /// This core trait for handling raw events
416+ /// An event handler that receives raw `dispatch` events.
417+ ///
418+ /// ## Warning
419+ /// As this is a low level trait, the methods of this trait are run on the same tokio task as the
420+ /// [`ShardRunner`].
421+ ///
422+ /// This means that if any of these methods take too long to return, the shard may drop events or be
423+ /// disconnected entirely.
424+ ///
425+ /// It is recommended to clone the fields needed out of [`Event`], then spawn a task to run
426+ /// concurrently to the shard loop.
419427#[ async_trait]
420428pub trait RawEventHandler : Send + Sync {
421429 /// Dispatched when any event occurs
@@ -425,15 +433,6 @@ pub trait RawEventHandler: Send + Sync {
425433 ///
426434 /// Returning `false` will drop an event and prevent it being dispatched by any frameworks and
427435 /// will exclude it from any collectors.
428- ///
429- /// ## Warning
430- ///
431- /// This will run synchronously on every event in the dispatch loop
432- /// of the shard that is receiving the event. If your filter code
433- /// takes too long, it may delay other events from being dispatched
434- /// in a timely manner. It is recommended to keep the runtime
435- /// complexity of the filter code low to avoid unnecessarily blocking
436- /// your bot.
437436 fn filter_event ( & self , _context : & Context , _event : & Event ) -> bool {
438437 // Suppress unused argument warnings
439438 true
0 commit comments