mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-02-10 21:43:16 +00:00
Merge wsutil fix from v1 into v2
This commit is contained in:
commit
33e7abd4db
|
@ -85,24 +85,26 @@ func (c *Conn) Dial(ctx context.Context, addr string) error {
|
||||||
// BUG which prevents stream compression.
|
// BUG which prevents stream compression.
|
||||||
// See https://github.com/golang/go/issues/31514.
|
// See https://github.com/golang/go/issues/31514.
|
||||||
|
|
||||||
conn, _, err := c.dialer.DialContext(ctx, addr, headers)
|
var err error
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "failed to dial WS")
|
|
||||||
}
|
|
||||||
|
|
||||||
events := make(chan Event, WSBuffer)
|
|
||||||
go startReadLoop(conn, events)
|
|
||||||
|
|
||||||
c.mutex.Lock()
|
c.mutex.Lock()
|
||||||
defer c.mutex.Unlock()
|
defer c.mutex.Unlock()
|
||||||
|
|
||||||
c.Conn = conn
|
c.Conn, _, err = c.dialer.DialContext(ctx, addr, headers)
|
||||||
c.events = events
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed to dial WS")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.events = make(chan Event, WSBuffer)
|
||||||
|
go startReadLoop(c.Conn, c.events)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) Listen() <-chan Event {
|
func (c *Conn) Listen() <-chan Event {
|
||||||
|
c.mutex.Lock()
|
||||||
|
defer c.mutex.Unlock()
|
||||||
|
|
||||||
return c.events
|
return c.events
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue