1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-01 04:24:19 +00:00

session: Fix Open not dying on ctx.Done

This commit is contained in:
diamondburned 2022-10-03 22:10:20 -07:00
parent d952c98829
commit a14fcb893a
No known key found for this signature in database
GPG key ID: D78C4471CE776659

View file

@ -236,9 +236,8 @@ func (s *Session) Open(ctx context.Context) error {
s.state.gateway = g s.state.gateway = g
} }
ctx, cancel := context.WithCancel(context.Background()) // Make a context that's stored in state so this can be used throughout.
s.state.ctx = ctx s.state.ctx, s.state.cancel = context.WithCancel(context.Background())
s.state.cancel = cancel
// TODO: change this to AddSyncHandler. // TODO: change this to AddSyncHandler.
rm := s.AddHandler(evCh) rm := s.AddHandler(evCh)
@ -253,6 +252,10 @@ func (s *Session) Open(ctx context.Context) error {
s.close() s.close()
return ctx.Err() return ctx.Err()
case <-s.state.ctx.Done():
s.close()
return s.state.ctx.Err()
case <-s.state.doneCh: case <-s.state.doneCh:
// Event loop died. // Event loop died.
return s.state.gateway.LastError() return s.state.gateway.LastError()