// Stop stops the scheduler.
779091
func (ttles *TTLExpirationScheduler) Stop() {
	ttles.Lock()
	defer ttles.Unlock()

	if err := ttles.writeState(); err != nil {
		dcontext.GetLogger(ttles.ctx).Errorf("Error writing scheduler state: %s", err)
	}

	for _, entry := range ttles.entries {
		entry.timer.Stop()
	}

	close(ttles.doneChan)
	ttles.saveTimer.Stop()
	ttles.stopped = true
}
828345
func (s *GrpcServer) Stop() {
	s.lock.Lock()
	defer s.lock.Unlock()

	if !s.running {
		return
	}

	s.server.Stop()
	s.wg.Wait()
	s.running = false
}
462655
func (t *Timer) Stop() bool {
	if t.timer != nil {
		return t.timer.Stop()
	}

	registered := !t.stopped
	t.mock.removeClockTimer((*internalTimer)(t))
	t.stopped = true
	return registered
}
225991
func (jst *Tracer) Stop(err error) {
	jst.reason = err
	atomic.StoreUint32(&jst.interrupt, 1)
}
259605
func (tm *Timer) Stop() {
	tm.mu.Lock()
	defer tm.mu.Unlock()
	if tm.running {
		tm.msg <- timerStop
		tm.running = false
	}
}
726950
func (m *Metrics) Stop(timer *MetricTimer) {
	if timer != nil {
		timer.Timer.UpdateSince(timer.Time)
	}
}
636160
func (d *Dispatcher) Stop() error {
	d.mu.Lock()
	if !d.isRunning() {
		d.mu.Unlock()
		return errors.New("dispatcher is already stopped")
	}

	log := log.G(d.ctx).WithField("method", "(*Dispatcher).Stop")
	log.Info("dispatcher stopping")
	d.cancel()
	d.mu.Unlock()

	d.processUpdatesLock.Lock()
	// when we called d.cancel(), there may be routines, servicing RPC calls to
	// the (*Dispatcher).Session endpoint, currently waiting at
	// d.processUpdatesCond.Wait() inside of (*Dispatcher).markNodeReady().
	//
	// these routines are typically woken by a call to
	// d.processUpdatesCond.Broadcast() at the end of
	// (*Dispatcher).processUpdates() as part of the main Run loop. However,
	// when d.cancel() is called, the main Run loop is stopped, and there are
	// no more opportunties for processUpdates to be called. Any calls to
	// Session would be stuck waiting on a call to Broadcast that will never
	// come.
	//
	// Further, because the rpcRW write lock cannot be obtained until every RPC
	// has exited and released its read lock, then Stop would be stuck forever.
	//
	// To avoid this case, we acquire the processUpdatesLock (so that no new
	// waits can start) and then do a Broadcast to wake all of the waiting
	// routines. Further, if any routines are waiting in markNodeReady to
	// acquire this lock, but not yet waiting, those routines will check the
	// context cancelation, see the context is canceled, and exit before doing
	// the Wait.
	//
	// This call to Broadcast must occur here. If we called Broadcast before
	// context cancelation, then some new routines could enter the wait. If we
	// call Broadcast after attempting to acquire the rpcRW lock, we will be
	// deadlocked. If we do this Broadcast without obtaining this lock (as is
	// done in the processUpdates method), then it would be possible for that
	// broadcast to come after the context cancelation check in markNodeReady,
	// but before the call to Wait.
	d.processUpdatesCond.Broadcast()
	d.processUpdatesLock.Unlock()

	// The active nodes list can be cleaned out only when all
	// existing RPCs have finished.
	// RPCs that start after rpcRW.Unlock() should find the context
	// cancelled and should fail organically.
	d.rpcRW.Lock()
	d.nodes.Clean()
	d.downNodes.Clean()
	d.rpcRW.Unlock()

	d.clusterUpdateQueue.Close()

	// TODO(anshul): This use of Wait() could be unsafe.
	// According to go's documentation on WaitGroup,
	// Add() with a positive delta that occur when the counter is zero
	// must happen before a Wait().
	// As is, dispatcher Stop() can race with Run().
	d.wg.Wait()

	return nil
}
719844
func (b *batchProducer) Stop() error {
	b.runningMu.Lock()
	defer b.runningMu.Unlock()

	if !b.running {
		return ErrAlreadyStopped
	}

	// request the main goroutine to stop
	b.stop <- true

	// block until the main goroutine returns a value indicating that it has stopped
	<-b.stop

	b.running = false

	return nil
}
1300252
func (c *Crontab) Stop() {
	if c.isTicker {
		if c.ticker != nil {
			c.ticker.Stop()
		}
	} else {
		c.stop = true
	}

}
42205
func (t *Ticker) Stop() {
	if t.ticker != nil {
		t.ticker.Stop()
	} else {
		t.mock.removeClockTimer((*internalTicker)(t))
	}
}
8193
func (r *sentReq) stop(err error) {
	r.lock.Lock()
	if !r.stopped {
		r.stopped = true
		r.err = err
		close(r.stopCh)
	}
	r.lock.Unlock()
}
691416
func (r *Orchestrator) Stop() {
	close(r.stopChan)
	<-r.doneChan
	r.updater.CancelAll()
	r.restarts.CancelAll()
}
1269136
func (d *Dispatcher) Stop() error {
	stopper := &PhasedStopper{
		dispatcher: d,
		log:        d.log,
	}
	return d.once.Stop(func() error {
		d.log.Info("shutting down dispatcher")
		return multierr.Combine(
			stopper.StopInbounds(),
			stopper.StopOutbounds(),
			stopper.StopTransports(),
		)
	})
}
866502
func (s *Server) Stop() {
	s.stopOnce.Do(func() {
		s.stopped = true
		s.listener.Close()
		close(s.startCh)
	})
}
576284
func (sit *SyncIntervalTimer) Stop() {
	sit.stop <- struct{}{}
	if sit.intervalTimer != nil {
		sit.intervalTimer.Stop()
	}
}
1219110
func (h *Handle) Stop() {
	h.l.Lock()
	defer h.l.Unlock()

	h.watcher.endQuery(h)
}
1208786
func (r *Consumer) Stop() {
	if !atomic.CompareAndSwapInt32(&r.stopFlag, 0, 1) {
		return
	}

	r.log(LogLevelInfo, "stopping...")

	if len(r.conns()) == 0 {
		r.stopHandlers()
	} else {
		for _, c := range r.conns() {
			err := c.WriteCommand(StartClose())
			if err != nil {
				r.log(LogLevelError, "(%s) error sending CLS - %s", c.String(), err)
			}
		}

		time.AfterFunc(time.Second*30, func() {
			// if we've waited this long handlers are blocked on processing messages
			// so we can't just stopHandlers (if any adtl. messages were pending processing
			// we would cause a panic on channel close)
			//
			// instead, we just bypass handler closing and skip to the final exit
			r.exit()
		})
	}
}