1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2025-12-02 01:29:47 +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:
diamondburned 2020-11-17 11:00:50 -08:00
parent 364f8388ed
commit d1242fc39a

View file

@ -131,14 +131,17 @@ func (v *Voice) GetSession(guildID discord.GuildID) (*Session, bool) {
// RemoveSession removes a session. // RemoveSession removes a session.
func (v *Voice) RemoveSession(guildID discord.GuildID) { func (v *Voice) RemoveSession(guildID discord.GuildID) {
v.mapmutex.Lock() v.mapmutex.Lock()
defer v.mapmutex.Unlock() ses, ok := v.sessions[guildID]
if !ok {
// Ensure that the session is disconnected. v.mapmutex.Unlock()
if ses, ok := v.sessions[guildID]; ok { return
ses.Disconnect()
} }
delete(v.sessions, guildID) delete(v.sessions, guildID)
v.mapmutex.Unlock()
// Ensure that the session is disconnected.
ses.Disconnect()
} }
// JoinChannel joins the specified channel in the specified guild. // JoinChannel joins the specified channel in the specified guild.