// WatchContext returns a channel where all items published to the queue will
// be received. The channel will be closed when the provided context is
// cancelled.
343389
func (q *Queue) WatchContext(ctx context.Context) (eventq chan events.Event) {
	return q.CallbackWatchContext(ctx, nil)
}
22067
func (api *Client) ArchiveGroupContext(ctx context.Context, group string) error {
	values := url.Values{
		"token":   {api.token},
		"channel": {group},
	}

	_, err := api.groupRequest(ctx, "groups.archive", values)
	return err
}
1202175
func (c *ChannelListCall) Context(ctx context.Context) *ChannelListCall {
	c.ctx_ = ctx
	return c
}
1143860
func (c *protectedContext) context() context.Context {
	c.mu.RLock()
	defer c.mu.RUnlock()
	return c.ctx
}
346006
func (o *UpdateTaskParams) WithContext(ctx context.Context) *UpdateTaskParams {
	o.SetContext(ctx)
	return o
}
958009
func (lk *etcdLock) watchLock() {
	keyName := "/contiv.io/lock/" + lk.name

	watcher := lk.kapi.Watcher(keyName, nil)
	if watcher == nil {
		log.Errorf("Error creating the watcher")
		return
	}
	for {
		resp, err := watcher.Next(lk.watchCtx)
		if err != nil && (err.Error() == client.ErrClusterUnavailable.Error() ||
			strings.Contains(err.Error(), "context canceled")) {
			log.Infof("Stopping watch on key %s", keyName)
			return
		} else if err != nil {
			log.Errorf("Error watching the key %s, Err %v.", keyName, err)
		} else {
			log.Debugf("Got Watch Resp: %+v", resp)

			// send the event to watch channel
			lk.watchCh <- resp
		}

		lk.mutex.Lock()
		// If the lock is released, we are done
		if lk.isReleased {
			lk.mutex.Unlock()
			return
		}
		lk.mutex.Unlock()
	}
}
398284
func (server *Server) ServeCodecWithContext(codec ServerCodec, context interface{}) {
	sending := new(sync.Mutex)
	eof := make(chan struct{})

	stopChans := make(map[uint64]chan struct{})
	var stopChansMtx sync.Mutex

	var contextVal reflect.Value
	if context != nil {
		contextVal = reflect.ValueOf(context)
	} else {
		contextVal = reflect.New(server.contextType)
	}
	for {
		service, mtype, req, argv, replyv, keepReading, err := server.readRequest(codec)
		if err != nil {
			if err == errCloseStream {
				go func() {
					stopChansMtx.Lock()
					stop, ok := stopChans[req.Seq]
					delete(stopChans, req.Seq)
					stopChansMtx.Unlock()
					if !ok {
						return
					}
					close(stop)
				}()
				continue
			}
			if !keepReading {
				break
			}
			// send a response if we actually managed to read a header.
			if req != nil {
				server.sendResponse(sending, req, invalidRequest, codec, err.Error(), true)
				server.freeRequest(req)
			}
			continue
		}

		done := make(chan struct{})
		stop := make(chan struct{})
		stopChansMtx.Lock()
		stopChans[req.Seq] = stop
		stopChansMtx.Unlock()

		go func(seq uint64) {
			<-done
			stopChansMtx.Lock()
			delete(stopChans, seq)
			stopChansMtx.Unlock()
		}(req.Seq)
		go service.call(call{
			server:  server,
			sending: sending,
			mtype:   mtype,
			req:     req,
			argv:    argv,
			replyv:  replyv,
			codec:   codec,
			context: contextVal,
			eof:     eof,
			done:    done,
			stop:    stop,
		})
	}
	close(eof)
	codec.Close()
}
965816
func (c *QueuesListCall) Context(ctx context.Context) *QueuesListCall {
	c.ctx_ = ctx
	return c
}
1283816
func (c *ChannelDeleteCall) Context(ctx context.Context) *ChannelDeleteCall {
	c.ctx_ = ctx
	return c
}
1367868
func (o *GetTaskCommentsParams) WithContext(ctx context.Context) *GetTaskCommentsParams {
	o.SetContext(ctx)
	return o
}
606149
func (wsc *wsConnection) Context() context.Context {
	if wsc.ctx != nil {
		return wsc.ctx
	}
	wsc.ctx, wsc.cancel = context.WithCancel(context.Background())
	return wsc.ctx
}
672811
func watchChannels(consumer *client.Consumer, cfg *client.Config) {

	for {
		select {
		case notification, more := <-cfg.RecvNotificationChan:
			if more {
				handleNotifcation(consumer, notification)
			}
		case err, more := <-cfg.RecvErrorChan:
			if more {
				fmt.Printf("Message Recv Errored: %v\n", err)
			}
		case msg, more := <-cfg.RecvMessageChan:
			if more {
				messageCallback(consumer, msg, *commit)
			}
		case <-consumer.GetCloseChannel():
			return
		}
	}
}
121540
func DialContext(ctx context.Context, urlstr string, opts ...DialOption) (*Conn, error) {
	d := &websocket.Dialer{
		ReadBufferSize:  25 * 1024 * 1024,
		WriteBufferSize: 10 * 1024 * 1024,
	}

	// connect
	conn, _, err := d.DialContext(ctx, urlstr, nil)
	if err != nil {
		return nil, err
	}

	// apply opts
	c := &Conn{
		conn: conn,
	}
	for _, o := range opts {
		o(c)
	}

	return c, nil
}
339068
func (api *Client) CloseIMChannelContext(ctx context.Context, channel string) (bool, bool, error) {
	values := url.Values{
		"token":   {api.token},
		"channel": {channel},
	}

	response, err := api.imRequest(ctx, "im.close", values)
	if err != nil {
		return false, false, err
	}
	return response.NoOp, response.AlreadyClosed, nil
}
896984
func (n *Node) WithContext(ctx context.Context) (context.Context, context.CancelFunc) {
	ctx, cancel := context.WithCancel(ctx)

	go func() {
		select {
		case <-ctx.Done():
		case <-n.stopped:
			cancel()
		}
	}()
	return ctx, cancel
}
37685
func (call *GetGroupMemberProfileCall) WithContext(ctx context.Context) *GetGroupMemberProfileCall {
	call.ctx = ctx
	return call
}
1051403
func (c *PeekCall) Context(ctx context.Context) *PeekCall {
	c.ctx_ = ctx
	return c
}