mempool: chan bool -> chan struct{}

This commit is contained in:
Ethan Buchman
2018-07-23 20:58:24 -04:00
parent 2aef80bcff
commit 15b112e669
3 changed files with 8 additions and 8 deletions

View File

@ -78,7 +78,7 @@ type Mempool struct {
recheckCursor *clist.CElement // next expected response recheckCursor *clist.CElement // next expected response
recheckEnd *clist.CElement // re-checking stops here recheckEnd *clist.CElement // re-checking stops here
notifiedTxsAvailable bool notifiedTxsAvailable bool
txsAvailable chan bool // fires once for each height, when the mempool is not empty txsAvailable chan struct{} // fires once for each height, when the mempool is not empty
// Keep a cache of already-seen txs. // Keep a cache of already-seen txs.
// This reduces the pressure on the proxyApp. // This reduces the pressure on the proxyApp.
@ -130,7 +130,7 @@ func NewMempool(
// ensuring it will trigger once every height when transactions are available. // ensuring it will trigger once every height when transactions are available.
// NOTE: not thread safe - should only be called once, on startup // NOTE: not thread safe - should only be called once, on startup
func (mem *Mempool) EnableTxsAvailable() { func (mem *Mempool) EnableTxsAvailable() {
mem.txsAvailable = make(chan bool, 1) mem.txsAvailable = make(chan struct{}, 1)
} }
// SetLogger sets the Logger. // SetLogger sets the Logger.
@ -348,7 +348,7 @@ func (mem *Mempool) resCbRecheck(req *abci.Request, res *abci.Response) {
// TxsAvailable returns a channel which fires once for every height, // TxsAvailable returns a channel which fires once for every height,
// and only when transactions are available in the mempool. // and only when transactions are available in the mempool.
// NOTE: the returned channel may be nil if EnableTxsAvailable was not called. // NOTE: the returned channel may be nil if EnableTxsAvailable was not called.
func (mem *Mempool) TxsAvailable() <-chan bool { func (mem *Mempool) TxsAvailable() <-chan struct{} {
return mem.txsAvailable return mem.txsAvailable
} }
@ -360,7 +360,7 @@ func (mem *Mempool) notifyTxsAvailable() {
// channel cap is 1, so this will send once // channel cap is 1, so this will send once
mem.notifiedTxsAvailable = true mem.notifiedTxsAvailable = true
select { select {
case mem.txsAvailable <- true: case mem.txsAvailable <- struct{}{}:
default: default:
} }
} }

View File

@ -38,7 +38,7 @@ func newMempoolWithApp(cc proxy.ClientCreator) *Mempool {
return mempool return mempool
} }
func ensureNoFire(t *testing.T, ch <-chan bool, timeoutMS int) { func ensureNoFire(t *testing.T, ch <-chan struct{}, timeoutMS int) {
timer := time.NewTimer(time.Duration(timeoutMS) * time.Millisecond) timer := time.NewTimer(time.Duration(timeoutMS) * time.Millisecond)
select { select {
case <-ch: case <-ch:
@ -47,7 +47,7 @@ func ensureNoFire(t *testing.T, ch <-chan bool, timeoutMS int) {
} }
} }
func ensureFire(t *testing.T, ch <-chan bool, timeoutMS int) { func ensureFire(t *testing.T, ch <-chan struct{}, timeoutMS int) {
timer := time.NewTimer(time.Duration(timeoutMS) * time.Millisecond) timer := time.NewTimer(time.Duration(timeoutMS) * time.Millisecond)
select { select {
case <-ch: case <-ch:

View File

@ -27,7 +27,7 @@ type Mempool interface {
Flush() Flush()
FlushAppConn() error FlushAppConn() error
TxsAvailable() <-chan bool TxsAvailable() <-chan struct{}
EnableTxsAvailable() EnableTxsAvailable()
} }
@ -43,7 +43,7 @@ func (m MockMempool) Reap(n int) types.Txs { retur
func (m MockMempool) Update(height int64, txs types.Txs) error { return nil } func (m MockMempool) Update(height int64, txs types.Txs) error { return nil }
func (m MockMempool) Flush() {} func (m MockMempool) Flush() {}
func (m MockMempool) FlushAppConn() error { return nil } func (m MockMempool) FlushAppConn() error { return nil }
func (m MockMempool) TxsAvailable() <-chan bool { return make(chan bool) } func (m MockMempool) TxsAvailable() <-chan struct{} { return make(chan struct{}) }
func (m MockMempool) EnableTxsAvailable() {} func (m MockMempool) EnableTxsAvailable() {}
//------------------------------------------------------ //------------------------------------------------------