@cryptotaxi247 / kubo / commits / 598585409

fix: return pointer

@whyrusleeping

Brian Tiger Chow committed Jan 19, 2015 at 02:35 UTC 598585409993a6c41ad2acd34d5cfb28bb84bb83
2 files changed +9 -6
exchange/bitswap/bitswap.go
+4 -1
@@ -281,7 +281,10 @@ func (bs *bitswap) taskWorker(ctx context.Context) {
281 select {
282 case <-ctx.Done():
283 return
284 - case envelope := <-nextEnvelope:
284 + case envelope, ok := <-nextEnvelope:
285 + if !ok {
286 + continue
287 + }
288 bs.send(ctx, envelope.Peer, envelope.Message)
289 }
290 }
exchange/bitswap/decision/engine.go
+5 -5
@@ -71,7 +71,7 @@ type Engine struct {
71
72 // outbox contains outgoing messages to peers. This is owned by the
73 // taskWorker goroutine
74 - outbox chan (<-chan Envelope)
74 + outbox chan (<-chan *Envelope)
75
76 bs bstore.Blockstore
77
@@ -85,7 +85,7 @@ func NewEngine(ctx context.Context, bs bstore.Blockstore) *Engine {
85 ledgerMap: make(map[peer.ID]*ledger),
86 bs: bs,
87 peerRequestQueue: newPRQ(),
88 - outbox: make(chan (<-chan Envelope), outboxChanBuffer),
88 + outbox: make(chan (<-chan *Envelope), outboxChanBuffer),
89 workSignal: make(chan struct{}),
90 }
91 go e.taskWorker(ctx)
@@ -95,7 +95,7 @@ func NewEngine(ctx context.Context, bs bstore.Blockstore) *Engine {
95 func (e *Engine) taskWorker(ctx context.Context) {
96 defer close(e.outbox) // because taskWorker uses the channel exclusively
97 for {
98 - oneTimeUse := make(chan Envelope, 1) // buffer to prevent blocking
98 + oneTimeUse := make(chan *Envelope, 1) // buffer to prevent blocking
99 select {
100 case <-ctx.Done():
101 return
@@ -108,7 +108,7 @@ func (e *Engine) taskWorker(ctx context.Context) {
108 close(oneTimeUse)
109 return // ctx cancelled
110 }
111 - oneTimeUse <- *envelope // buffered. won't block
111 + oneTimeUse <- envelope // buffered. won't block
112 close(oneTimeUse)
113 }
114 }
@@ -141,7 +141,7 @@ func (e *Engine) nextEnvelope(ctx context.Context) (*Envelope, error) {
141 }
142
143 // Outbox returns a channel of one-time use Envelope channels.
144 -func (e *Engine) Outbox() <-chan (<-chan Envelope) {
144 +func (e *Engine) Outbox() <-chan (<-chan *Envelope) {
145 return e.outbox
146 }
147