mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-10-31 20:14:21 +00:00
session: Fix Open not dying on ctx.Done
This commit is contained in:
parent
d952c98829
commit
a14fcb893a
|
@ -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()
|
||||||
|
|
Loading…
Reference in a new issue