select with context when sending on channels
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Jun 12, 2015 at 11:32 UTC
b12cc09f64a67848ab930928cb253e16232b703a
1 file changed
+8
-2
exchange/bitswap/wantmanager.go
+8
-2
@@ -168,11 +168,17 @@ func (mq *msgQueue) runQueue(ctx context.Context) {
168
}
169
170
func (pm *WantManager) Connected(p peer.ID) {
171
- pm.connect <- p
171
+ select {
172
+ case pm.connect <- p:
173
+ case <-pm.ctx.Done():
174
+ }
175
}
176
177
func (pm *WantManager) Disconnected(p peer.ID) {
175
- pm.disconnect <- p
178
+ select {
179
+ case pm.disconnect <- p:
180
+ case <-pm.ctx.Done():
181
+ }
182
}
183
184
// TODO: use goprocess here once i trust it