Skip to content

Commit

Permalink
fix: return pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Tiger Chow committed Jan 19, 2015
1 parent 60e288e commit 5985854
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion exchange/bitswap/bitswap.go
Expand Up @@ -281,7 +281,10 @@ func (bs *bitswap) taskWorker(ctx context.Context) {
select {
case <-ctx.Done():
return
case envelope := <-nextEnvelope:
case envelope, ok := <-nextEnvelope:
if !ok {
continue
}
bs.send(ctx, envelope.Peer, envelope.Message)
}
}
Expand Down
10 changes: 5 additions & 5 deletions exchange/bitswap/decision/engine.go
Expand Up @@ -71,7 +71,7 @@ type Engine struct {

// outbox contains outgoing messages to peers. This is owned by the
// taskWorker goroutine
outbox chan (<-chan Envelope)
outbox chan (<-chan *Envelope)

bs bstore.Blockstore

Expand All @@ -85,7 +85,7 @@ func NewEngine(ctx context.Context, bs bstore.Blockstore) *Engine {
ledgerMap: make(map[peer.ID]*ledger),
bs: bs,
peerRequestQueue: newPRQ(),
outbox: make(chan (<-chan Envelope), outboxChanBuffer),
outbox: make(chan (<-chan *Envelope), outboxChanBuffer),
workSignal: make(chan struct{}),
}
go e.taskWorker(ctx)
Expand All @@ -95,7 +95,7 @@ func NewEngine(ctx context.Context, bs bstore.Blockstore) *Engine {
func (e *Engine) taskWorker(ctx context.Context) {
defer close(e.outbox) // because taskWorker uses the channel exclusively
for {
oneTimeUse := make(chan Envelope, 1) // buffer to prevent blocking
oneTimeUse := make(chan *Envelope, 1) // buffer to prevent blocking
select {
case <-ctx.Done():
return
Expand All @@ -108,7 +108,7 @@ func (e *Engine) taskWorker(ctx context.Context) {
close(oneTimeUse)
return // ctx cancelled
}
oneTimeUse <- *envelope // buffered. won't block
oneTimeUse <- envelope // buffered. won't block
close(oneTimeUse)
}
}
Expand Down Expand Up @@ -141,7 +141,7 @@ func (e *Engine) nextEnvelope(ctx context.Context) (*Envelope, error) {
}

// Outbox returns a channel of one-time use Envelope channels.
func (e *Engine) Outbox() <-chan (<-chan Envelope) {
func (e *Engine) Outbox() <-chan (<-chan *Envelope) {
return e.outbox
}

Expand Down

0 comments on commit 5985854

Please sign in to comment.