rewrite broadcastTxRoutine to use channels

https://play.golang.org/p/gN21yO9IRs3

```
func waitWithCancel(f func() *clist.CElement, ctx context.Context) *clist.CElement {
	el := make(chan *clist.CElement, 1)
	select {
	case el <- f():
```
will just run f() blockingly, so this doesn't change much in terms of behavior.
This commit is contained in:
Anton Kaliaev
2018-02-01 18:33:33 +04:00
parent 202d9a2c0c
commit 11b68f1934
7 changed files with 58 additions and 50 deletions

View File

@ -18,6 +18,7 @@ import (
// Peer is an interface representing a peer connected on a reactor.
type Peer interface {
cmn.Service
QuitChan() <-chan struct{}
ID() ID // peer's cryptographic ID
IsOutbound() bool // did we dial the peer
@ -331,6 +332,11 @@ func (p *peer) String() string {
return fmt.Sprintf("Peer{%v %v in}", p.mconn, p.ID())
}
// QuitChan returns a channel, which will be closed once peer is stopped.
func (p *peer) QuitChan() <-chan struct{} {
return p.Quit
}
//------------------------------------------------------------------
// helper funcs