1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-10-04 00:29:04 +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:
diamondburned 2022-10-03 22:37:40 -07:00
parent a14fcb893a
commit 1af71182d0
No known key found for this signature in database
GPG key ID: D78C4471CE776659

View file

@ -32,6 +32,14 @@ type Session struct {
// internal state to not be copied around. // internal state to not be copied around.
state *sessionState 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 { type sessionState struct {
@ -261,6 +269,10 @@ func (s *Session) Open(ctx context.Context) error {
return s.state.gateway.LastError() return s.state.gateway.LastError()
case ev := <-evCh: case ev := <-evCh:
if s.DontWaitForReady {
return nil
}
switch ev.(type) { switch ev.(type) {
case *gateway.ReadyEvent, *gateway.ResumedEvent: case *gateway.ReadyEvent, *gateway.ResumedEvent:
return nil return nil