Use WithContextAndTeardown whenever possible
License: MIT Signed-off-by: rht <rhtbot@gmail.com>
rht committed
Jun 22, 2015 at 21:57 UTC
0ceac5ded9083b168d47f12b85793ac5035baf01
5 files changed
+7
-13
core/core.go
+2
-4
@@ -128,15 +128,13 @@ func NewIPFSNode(ctx context.Context, option ConfigOption) (*IpfsNode, error) {
128
return nil, err
129
}
130
131
- proc := goprocessctx.WithContext(ctx)
132
- proc.SetTeardown(node.teardown)
133
- node.proc = proc
131
+ node.proc = goprocessctx.WithContextAndTeardown(ctx, node.teardown)
132
node.ctx = ctx
133
134
success := false // flip to true after all sub-system inits succeed
135
defer func() {
136
if !success {
139
- proc.Close()
137
+ node.proc.Close()
138
}
139
}()
140
p2p/net/conn/listen.go
+1
-2
@@ -158,9 +158,8 @@ func Listen(ctx context.Context, addr ma.Multiaddr, local peer.ID, sk ic.PrivKey
158
Listener: ml,
159
local: local,
160
privk: sk,
161
- proc: goprocessctx.WithContext(ctx),
161
}
163
- l.proc.SetTeardown(l.teardown)
162
+ l.proc = goprocessctx.WithContextAndTeardown(ctx, l.teardown)
163
164
log.Debugf("Conn Listener on %s", l.Multiaddr())
165
log.Event(ctx, "swarmListen", l)
p2p/net/mock/mock_peernet.go
+1
-2
@@ -58,7 +58,6 @@ func newPeernet(ctx context.Context, m *mocknet, k ic.PrivKey,
58
mocknet: m,
59
peer: p,
60
ps: ps,
61
- proc: goprocessctx.WithContext(ctx),
61
62
connsByPeer: map[peer.ID]map[*conn]struct{}{},
63
connsByLink: map[*link]map[*conn]struct{}{},
@@ -66,7 +65,7 @@ func newPeernet(ctx context.Context, m *mocknet, k ic.PrivKey,
65
notifs: make(map[inet.Notifiee]struct{}),
66
}
67
69
- n.proc.SetTeardown(n.teardown)
68
+ n.proc = goprocessctx.WithContextAndTeardown(ctx, n.teardown)
69
return n, nil
70
}
71
p2p/net/swarm/swarm.go
+1
-2
@@ -82,7 +82,6 @@ func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr,
82
swarm: ps.NewSwarm(PSTransport),
83
local: local,
84
peers: peers,
85
- proc: goprocessctx.WithContext(ctx),
85
ctx: ctx,
86
dialT: DialTimeout,
87
notifs: make(map[inet.Notifiee]ps.Notifiee),
@@ -91,7 +90,7 @@ func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr,
90
}
91
92
// configure Swarm
94
- s.proc.SetTeardown(s.teardown)
93
+ s.proc = goprocessctx.WithContextAndTeardown(ctx, s.teardown)
94
s.SetConnHandler(nil) // make sure to setup our own conn handler.
95
96
// setup swarm metrics
routing/dht/dht.go
+2
-3
@@ -73,13 +73,12 @@ func NewDHT(ctx context.Context, h host.Host, dstore ds.ThreadSafeDatastore) *Ip
73
// register for network notifs.
74
dht.host.Network().Notify((*netNotifiee)(dht))
75
76
- proc := goprocessctx.WithContext(ctx)
77
- proc.SetTeardown(func() error {
76
+ dht.proc = goprocessctx.WithContextAndTeardown(ctx, func() error {
77
// remove ourselves from network notifs.
78
dht.host.Network().StopNotify((*netNotifiee)(dht))
79
return nil
80
})
82
- dht.proc = proc
81
+
82
dht.ctx = ctx
83
84
h.SetStreamHandler(ProtocolDHT, dht.handleNewStream)