// removeReplySubTimeout will remove a timer if it exists.
// Lock should be held upon entering.
544937
func (c *client) removeReplySubTimeout(sub *subscription) {
	// Remove any reply sub timer if it exists.
	if c.route == nil || c.route.replySubs == nil {
		return
	}
	if t, ok := c.route.replySubs[sub]; ok {
		t.Stop()
		delete(c.route.replySubs, sub)
	}
}
972821
func (lc *LightChain) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription {
	return lc.scope.Track(new(event.Feed).Subscribe(ch))
}
803292
func (p *Pubsub) Unsubscribe(ev EventBuilder, l Listener) {
	timer := gaugeLatency(PromSubLatency)
	defer timer()

	p.subsMu.Lock()
	count := p.subs[ev.kind].Remove(ev, l)
	p.subsMu.Unlock()

	if count == 0 {
		PromSubscriptions.Dec()
		written := make(chan struct{}, 1)
		p.send <- command{
			command: ev.kind.UnsubCommand(),
			channel: ev.Name(),
			written: written,
		}

		<-written
	}
}
290454
func (s *Semaphore) TryAcquireTimeout(d time.Duration) bool {
	select {
	case s.sch <- struct{}{}:
		return true
	case <-time.After(d):
		return false
	}
}
233473
func (s *SyncStatusSubscription) Unsubscribe() {
	s.unsubOnce.Do(func() {
		req := uninstallSyncSubscriptionRequest{s.c, make(chan interface{})}
		s.api.uninstallSyncSubscription <- &req

		for {
			select {
			case <-s.c:
				// drop new status events until uninstall confirmation
				continue
			case <-req.uninstalled:
				return
			}
		}
	})
}
612393
func EventRemoveTimeout(timer int) error {
	var err C.virError
	ret := C.virEventRemoveTimeoutWrapper((C.int)(timer), &err)
	if ret < 0 {
		return makeError(&err)
	}

	return nil
}
914070
func (nc *Conn) removeSub(s *Subscription) {
	nc.subsMu.Lock()
	delete(nc.subs, s.sid)
	nc.subsMu.Unlock()
	s.mu.Lock()
	defer s.mu.Unlock()
	// Release callers on NextMsg for SyncSubscription only
	if s.mch != nil && s.typ == SyncSubscription {
		close(s.mch)
	}
	s.mch = nil

	// Mark as invalid
	s.conn = nil
	s.closed = true
	if s.pCond != nil {
		s.pCond.Broadcast()
	}
}
1255856
func (e *EventListener) Unsubscribe(s *EventSubscriber) {
	e.subMtx.Lock()
	defer e.subMtx.Unlock()
	if subs, ok := e.subscribers[s.appID]; ok {
		delete(subs, s)
		if len(subs) == 0 {
			delete(e.subscribers, s.appID)
		}
	}
}
576986
func (b *eventListenerSupport) removeListener(substr string, listener <-chan string) {
	b.Lock()
	defer b.Unlock()
	if listeners, ok := b.listeners[substr]; ok {
		for i, l := range listeners {
			if l == listener {
				copy(listeners[i:], listeners[i+1:])
				listeners[len(listeners)-1] = nil
				b.listeners[substr] = listeners[:len(listeners)-1]
			}
		}
	}
}
695523
func (s *Service) stopTimeout(timeout int) int {
	DEFAULTTIMEOUT := 10
	if timeout != 0 {
		return timeout
	}
	configTimeout := utils.DurationStrToSecondsInt(s.Config().StopGracePeriod)
	if configTimeout != nil {
		return *configTimeout
	}
	return DEFAULTTIMEOUT
}
1132800
func (mr *MockFeedMockRecorder) Unsubscribed() *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Unsubscribed", reflect.TypeOf((*MockFeed)(nil).Unsubscribed))
}
278114
func eventRemoveTimeoutFunc(timer C.int) {
	if eventLoopImpl == nil {
		panic("Event loop impl is missing")
	}

	eventLoopImpl.RemoveTimeoutFunc(int(timer))
}
259135
func (m *SubscriptionManager) handleCancelSubscription(msg *cancelSubscription) {
	// First, we'll attempt to look up an existing susbcriber with the given
	// ID.
	sub, ok := m.subscribers[msg.id]
	if !ok {
		return
	}

	log.Infof("Canceling block subscription: id=%d", msg.id)

	// If there is one, we'll stop their internal queue to no longer deliver
	// notifications to them.
	delete(m.subscribers, msg.id)
	sub.cancel()
}
147617
func (em *clientEventMonitor) unsubscribe(s *Subscription) error {
	em.Lock()
	defer em.Unlock()

	ns := []*Subscription{}
	for _, sub := range em.subscriptions[s.ID] {
		if sub != s {
			ns = append(ns, sub)
		}
	}

	em.subscriptions[s.ID] = ns

	return nil
}
672805
func (c *Client) Unsubscribe(ctx context.Context, id string) error {
	sub, err := c.subscriptions.lookupBySubscriptionID(id)
	if err != nil {
		return err
	}
	// sub is removed from manager on ack from API
	return c.sendUnsubscribeMessage(ctx, sub.ChanID)
}
248057
func (m *SubscriptionManager) cancelSubscription(sub *newSubscription) {
	select {
	case m.cancelSubscriptions <- &cancelSubscription{sub.id}:
	case <-m.quit:
	}
}
308664
func (s *subscriptions) removeBySubscriptionID(subID string) error {
	s.lock.Lock()
	defer s.lock.Unlock()
	sub, ok := s.subsBySubID[subID]
	if !ok {
		return fmt.Errorf("could not find subscription ID %s to remove", subID)
	}
	// exists, remove both indices
	delete(s.subsBySubID, subID)
	if _, ok = s.subsByChanID[sub.ChanID]; ok {
		delete(s.subsByChanID, sub.ChanID)
	}
	return nil
}