// callback is spawned in a goroutine
callback is spawned in a goroutine
// callback is spawned in a goroutine
func (c *Client) pollWS(path string, callback func(*fastjson.Value)) (func(), error) {
	ws, err := c.EstablishWS(path)
	if err != nil {
		return nil, err
	}
	go func() {
		for {
			_, message, err := ws.ReadMessage()
			if err != nil {
				c.OnError(err)
				return
			}
			go func(message []byte) {
				p := c.jsonPool.Get()
				defer c.jsonPool.Put(p)
				o, err := p.ParseBytes(message)
				if err != nil {
					c.OnError(err)
					return
				}
				callback(o)
			}(message)
		}
	}()
	cancel := func() {
		ws.Close()
	}
	c.stopSockets = append(c.stopSockets, cancel)
	return cancel, nil
}
func ( c * Client ) pollWS ( path string , callback func ( * fastjson . Value ) ) ( func ( ) , error ) { ws , err := c . EstablishWS ( path ) if err != nil { return nil , err } go func ( ) { for { _ , message , err := ws . ReadMessage ( ) if err != nil { c . OnError ( err ) return } go func ( message [ ] byte ) { p := c . jsonPool . Get ( ) defer c . jsonPool . Put ( p ) o , err := p . ParseBytes ( message ) if err != nil { c . OnError ( err ) return } callback ( o ) } ( message ) } } ( ) cancel := func ( ) { ws . Close ( ) } c . stopSockets = append ( c . stopSockets , cancel ) return cancel , nil }
callback is spawned in a goroutine
callback is spawned in a goroutine
// Also kills the for loop above