@cryptotaxi247 / kubo / commits / f53367872

avoid attaching context to object when it's not necessary.

License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>

Brian Tiger Chow committed Dec 15, 2014 at 23:00 UTC f533678724c655446cb1d5534283ad5923da9fab
1 file changed +4 -6
exchange/bitswap/strategy/ledgermanager.go
+4 -6
@@ -27,7 +27,6 @@ type LedgerManager struct {
27 tasklist *TaskList
28 taskOut chan *Task
29 workSignal chan struct{}
30 - ctx context.Context
30 }
31
32 func NewLedgerManager(bs bstore.Blockstore, ctx context.Context) *LedgerManager {
@@ -37,20 +36,19 @@ func NewLedgerManager(bs bstore.Blockstore, ctx context.Context) *LedgerManager
36 tasklist: NewTaskList(),
37 taskOut: make(chan *Task, 4),
38 workSignal: make(chan struct{}),
40 - ctx: ctx,
39 }
42 - go lm.taskWorker()
40 + go lm.taskWorker(ctx)
41 return lm
42 }
43
46 -func (lm *LedgerManager) taskWorker() {
44 +func (lm *LedgerManager) taskWorker(ctx context.Context) {
45 for {
46 nextTask := lm.tasklist.Pop()
47 if nextTask == nil {
48 // No tasks in the list?
49 // Wait until there are!
50 select {
53 - case <-lm.ctx.Done():
51 + case <-ctx.Done():
52 return
53 case <-lm.workSignal:
54 }
@@ -58,7 +56,7 @@ func (lm *LedgerManager) taskWorker() {
56 }
57
58 select {
61 - case <-lm.ctx.Done():
59 + case <-ctx.Done():
60 return
61 case lm.taskOut <- nextTask:
62 }