Skip to content

Commit

Permalink
Docs: Warn about twilight task deadlock
Browse files Browse the repository at this point in the history
Potential deadlock (identified by a user) has now been warned about. The way the example is structured prevents this from occurring, but it's worth making this more explicit due to the more free-form nature of twilight.

The design of serenity's event handling and framework should prevent this issue from cropping up when using it as a gateway backend.
  • Loading branch information
FelixMcFelix committed Dec 27, 2020
1 parent 504b8df commit c0d3cb3
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,11 @@ impl Songbird {
/// If you _only_ need to retrieve the handler for a target, then use
/// [`get`].
///
/// Twilight users should read the caveats mentioned in [`process`].
///
/// [`Call`]: Call
/// [`get`]: Songbird::get
/// [`process`]: #method.process
#[inline]
pub async fn join<C, G>(&self, guild_id: G, channel_id: C) -> (Arc<Mutex<Call>>, JoinResult<()>)
where
Expand Down Expand Up @@ -310,6 +313,17 @@ impl Songbird {
///
/// When using twilight, you are required to call this with all inbound
/// (voice) events, *i.e.*, at least `VoiceStateUpdate`s and `VoiceServerUpdate`s.
///
/// Users *must* ensure that calls to this function happen on a **separate task**
/// to any calls to [`join`], [`join_gateway`]. The simplest way to ensure this is
/// to `tokio::spawn` any command invocation.
///
/// Returned futures generally require the inner [`Call`] to be updated via this function,
/// and will deadlock if event processing is not carried out on another spawned task.
///
/// [`join`]: Songbird::join
/// [`join_gateway`]: Songbird::join_gateway
/// [`Call`]: Call
pub async fn process(&self, event: &TwilightEvent) {
match event {
TwilightEvent::VoiceServerUpdate(v) => {
Expand Down

0 comments on commit c0d3cb3

Please sign in to comment.