mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-02-08 20:47:13 +00:00
Voice: Remove Session from repository before disconnecting
This commit introduces this change so that Voice can be called from other threads without waiting for one Session to disconnect itself.
This commit is contained in:
parent
364f8388ed
commit
d1242fc39a
|
@ -131,14 +131,17 @@ func (v *Voice) GetSession(guildID discord.GuildID) (*Session, bool) {
|
|||
// RemoveSession removes a session.
|
||||
func (v *Voice) RemoveSession(guildID discord.GuildID) {
|
||||
v.mapmutex.Lock()
|
||||
defer v.mapmutex.Unlock()
|
||||
|
||||
// Ensure that the session is disconnected.
|
||||
if ses, ok := v.sessions[guildID]; ok {
|
||||
ses.Disconnect()
|
||||
ses, ok := v.sessions[guildID]
|
||||
if !ok {
|
||||
v.mapmutex.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
delete(v.sessions, guildID)
|
||||
v.mapmutex.Unlock()
|
||||
|
||||
// Ensure that the session is disconnected.
|
||||
ses.Disconnect()
|
||||
}
|
||||
|
||||
// JoinChannel joins the specified channel in the specified guild.
|
||||
|
|
Loading…
Reference in a new issue