Make subscribeToEvent have capacity 1

This commit is contained in:
Jae Kwon
2016-01-18 12:18:09 -08:00
parent 892174997b
commit 8be32257e7
2 changed files with 62 additions and 52 deletions

View File

@ -9,9 +9,9 @@ import (
"time"
dbm "github.com/tendermint/go-db"
"github.com/tendermint/go-events"
bc "github.com/tendermint/tendermint/blockchain"
_ "github.com/tendermint/tendermint/config/tendermint_test"
"github.com/tendermint/go-events"
mempl "github.com/tendermint/tendermint/mempool"
"github.com/tendermint/tendermint/proxy"
sm "github.com/tendermint/tendermint/state"
@ -339,7 +339,7 @@ func simpleConsensusState(nValidators int) (*ConsensusState, []*validatorStub) {
}
func subscribeToVoter(cs *ConsensusState, addr []byte) chan interface{} {
voteCh0 := cs.evsw.SubscribeToEvent("tester", types.EventStringVote(), 0)
voteCh0 := subscribeToEvent(cs.evsw, "tester", types.EventStringVote(), 1)
voteCh := make(chan interface{})
go func() {
for {
@ -386,3 +386,13 @@ func startTestRound(cs *ConsensusState, height, round int) {
cs.enterNewRound(height, round)
cs.startRoutines(0)
}
// NOTE: this is blocking
func subscribeToEvent(evsw *events.EventSwitch, receiver, eventID string, chanCap int) chan interface{} {
// listen for new round
ch := make(chan interface{}, chanCap)
evsw.AddListenerForEvent(receiver, eventID, func(data events.EventData) {
ch <- data
})
return ch
}