1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-27 17:23:00 +00:00

voice: Close previous UDP sessions on Continue (#358)

This commit is contained in:
Jason Chu 2022-12-03 19:39:43 -08:00 committed by GitHub
parent 12a84ee999
commit 4db60bca9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -28,6 +28,7 @@ type Manager struct {
// conn state
conn *Connection
prevConn *Connection
connLock chan struct{}
frequency time.Duration
@ -69,6 +70,7 @@ func (m *Manager) Pause(ctx context.Context) error {
case <-ctx.Done():
return ctx.Err()
case m.connLock <- struct{}{}:
m.prevConn = m.conn
return nil
}
}
@ -113,6 +115,11 @@ func (m *Manager) IsClosed() bool {
func (m *Manager) Continue() bool {
ws.WSDebug("UDP continued")
if m.prevConn != nil {
m.prevConn.Close()
m.prevConn = nil
}
select {
case <-m.connLock:
return true