func (b *EvalBatcher) batcher() {
	var timerCh <-chan time.Time
	evals := make(map[string]*structs.Evaluation)
	for {
		select {
		case <-b.ctx.Done():
			return
		case e := <-b.inCh:
			if timerCh == nil {
				timerCh = time.After(b.batch)
			}

			evals[e.DeploymentID] = e
		case <-timerCh:
			// Capture the future
			b.l.Lock()
			f := b.f
			b.f = nil
			b.l.Unlock()

			// Shouldn't be possible
			if f == nil {
				panic("no future")
			}

			// Capture the evals
			all := make([]*structs.Evaluation, 0, len(evals))
			for _, e := range evals {
				all = append(all, e)
			}

			// Upsert the evals in a go routine
			go f.Set(b.raft.UpsertEvals(all))

			// Reset the evals list and timer
			evals = make(map[string]*structs.Evaluation)
			timerCh = nil

		}
	}
}
// batcher is the long lived batcher goroutine
batcher is the long lived batcher goroutine
// batcher is the long lived batcher goroutine
func (b *EvalBatcher) batcher() {
	var timerCh <-chan time.Time
	evals := make(map[string]*structs.Evaluation)
	for {
		select {
		case <-b.ctx.Done():
			return
		case e := <-b.inCh:
			if timerCh == nil {
				timerCh = time.After(b.batch)
			}
			evals[e.DeploymentID] = e
		case <-timerCh:
			b.l.Lock()
			f := b.f
			b.f = nil
			b.l.Unlock()
			if f == nil {
				panic("no future")
			}
			all := make([]*structs.Evaluation, 0, len(evals))
			for _, e := range evals {
				all = append(all, e)
			}
			go f.Set(b.raft.UpsertEvals(all))
			evals = make(map[string]*structs.Evaluation)
			timerCh = nil
		}
	}
}
func ( b * EvalBatcher ) batcher ( ) { var timerCh <- chan time . Time evals := make ( map [ string ] * structs . Evaluation ) for { select { case <- b . ctx . Done ( ) : return case e := <- b . inCh : if timerCh == nil { timerCh = time . After ( b . batch ) } evals [ e . DeploymentID ] = e case <- timerCh : b . l . Lock ( ) f := b . f b . f = nil b . l . Unlock ( ) if f == nil { panic ( " " ) } all := make ( [ ] * structs . Evaluation , 0 , len ( evals ) ) for _ , e := range evals { all = append ( all , e ) } go f . Set ( b . raft . UpsertEvals ( all ) ) evals = make ( map [ string ] * structs . Evaluation ) timerCh = nil } } }
batcher is the long lived batcher goroutine
batcher is the long lived batcher goroutine
// Capture the future // Shouldn't be possible // Capture the evals // Upsert the evals in a go routine // Reset the evals list and timer