mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-10-31 20:14:21 +00:00
session: Add DontWaitForReady
This is a workaround for some cases where ReadyEvent cannot be delivered successfully, e.g. in the case of an unmarshal failure. We should handle BackgroundErrorEvents in the future that fatally exits on any unmarshal errors.
This commit is contained in:
parent
a14fcb893a
commit
1af71182d0
|
@ -32,6 +32,14 @@ type Session struct {
|
|||
|
||||
// internal state to not be copied around.
|
||||
state *sessionState
|
||||
|
||||
// Options, all of which default to the zero value.
|
||||
|
||||
// DontWaitForReady makes Open not wait for the Ready event. This is useful
|
||||
// for non-bots, since Discord may send over a READY_SUPPLEMENT instead. If
|
||||
// this is true, then any event sent by Discord will unblock Open (usually
|
||||
// HELLO).
|
||||
DontWaitForReady bool
|
||||
}
|
||||
|
||||
type sessionState struct {
|
||||
|
@ -261,6 +269,10 @@ func (s *Session) Open(ctx context.Context) error {
|
|||
return s.state.gateway.LastError()
|
||||
|
||||
case ev := <-evCh:
|
||||
if s.DontWaitForReady {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch ev.(type) {
|
||||
case *gateway.ReadyEvent, *gateway.ResumedEvent:
|
||||
return nil
|
||||
|
|
Loading…
Reference in a new issue