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
1 changed files with 12 additions and 0 deletions

View File

@ -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