tendermint/consensus/common.go

30 lines
949 B
Go
Raw Normal View History

package consensus
import (
2016-10-09 23:58:13 -07:00
"github.com/tendermint/tendermint/types"
)
2016-12-22 18:51:58 -08:00
// XXX: WARNING: these functions can halt the consensus as firing events is synchronous.
// Make sure to read off the channels, and in the case of subscribeToEventRespond, to write back on it
2016-11-23 15:20:46 -08:00
// NOTE: if chanCap=0, this blocks on the event being consumed
2016-10-09 23:58:13 -07:00
func subscribeToEvent(evsw types.EventSwitch, receiver, eventID string, chanCap int) chan interface{} {
2016-06-25 21:40:53 -07:00
// listen for event
ch := make(chan interface{}, chanCap)
2016-10-09 23:58:13 -07:00
types.AddListenerForEvent(evsw, receiver, eventID, func(data types.TMEventData) {
ch <- data
})
return ch
}
2016-11-23 15:20:46 -08:00
// NOTE: this blocks on receiving a response after the event is consumed
func subscribeToEventRespond(evsw types.EventSwitch, receiver, eventID string) chan interface{} {
// listen for event
ch := make(chan interface{})
types.AddListenerForEvent(evsw, receiver, eventID, func(data types.TMEventData) {
ch <- data
<-ch
})
return ch
}