in pkg/dispatcher/dispatcher.go [243:284]
func Stop() {
log.Log(log.ShimDispatcher).Info("stopping the dispatcher")
var chanClosed bool
select {
case <-getDispatcher().stopChan:
chanClosed = true
default:
}
if chanClosed {
if getDispatcher().isRunning() {
log.Log(log.ShimDispatcher).Info("dispatcher shutdown in progress")
} else {
log.Log(log.ShimDispatcher).Info("dispatcher is already stopped")
}
return
}
close(getDispatcher().stopChan)
stopWait := make(chan struct{})
go func() {
defer close(stopWait)
getDispatcher().stopped.Wait()
}()
// wait until the main event loop stops properly
select {
case <-stopWait:
break
case <-time.After(5 * time.Second):
log.Log(log.ShimDispatcher).Info("dispatcher did not stop in time")
break
}
if getDispatcher().isRunning() {
log.Log(log.ShimDispatcher).Warn("dispatcher even processing did not stop properly")
} else {
log.Log(log.ShimDispatcher).Info("dispatcher stopped successfully")
}
}