// OnStop stops the reactor by signaling to all spawned goroutines to exit and
// blocking until they all exit, as well as unsubscribing from events and stopping
// state.
OnStop stops the reactor by signaling to all spawned goroutines to exit and
blocking until they all exit, as well as unsubscribing from events and stopping
state.
// OnStop stops the reactor by signaling to all spawned goroutines to exit and // blocking until they all exit as well as unsubscribing from events and stopping // state .
func (r *Reactor) OnStop() {
	r.unsubscribeFromBroadcastEvents()
	if err := r.state.Stop(); err != nil {
		r.Logger.Error("failed to stop consensus state", "err", err)
	}
	if !r.WaitSync() {
		r.state.Wait()
	}
	r.mtx.Lock()
	peers := r.peers
	r.mtx.Unlock()
	for _, ps := range peers {
		ps.closer.Close()
	}
	for _, ps := range peers {
		ps.broadcastWG.Wait()
	}
	close(r.stateCloseCh)
	<-r.stateCh.Done()
	close(r.closeCh)
	<-r.voteSetBitsCh.Done()
	<-r.dataCh.Done()
	<-r.voteCh.Done()
	<-r.peerUpdates.Done()
}
func ( r * Reactor ) OnStop ( ) { r . unsubscribeFromBroadcastEvents ( ) if err := r . state . Stop ( ) ; err != nil { r . Logger . Error ( " " , " " , err ) } if ! r . WaitSync ( ) { r . state . Wait ( ) } r . mtx . Lock ( ) peers := r . peers r . mtx . Unlock ( ) for _ , ps := range peers { ps . closer . Close ( ) } for _ , ps := range peers { ps . broadcastWG . Wait ( ) } close ( r . stateCloseCh ) <- r . stateCh . Done ( ) close ( r . closeCh ) <- r . voteSetBitsCh . Done ( ) <- r . dataCh . Done ( ) <- r . voteCh . Done ( ) <- r . peerUpdates . Done ( ) }
OnStop stops the reactor by signaling to all spawned goroutines to exit and
blocking until they all exit, as well as unsubscribing from events and stopping
state.
OnStop stops the reactor by signaling to all spawned goroutines to exit and blocking until they all exit as well as unsubscribing from events and stopping state .
// wait for all spawned peer goroutines to gracefully exit // Close the StateChannel goroutine separately since it uses its own channel // to signal closure. // Close closeCh to signal to all spawned goroutines to gracefully exit. All // p2p Channels should execute Close(). // Wait for all p2p Channels to be closed before returning. This ensures we // can easily reason about synchronization of all p2p Channels and ensure no // panics will occur.