@cryptotaxi247 / kubo / commits / 97e11c7d0

fix(do) child listens on ctx too

Brian Tiger Chow committed Nov 5, 2014 at 06:53 UTC 97e11c7d01d3c05eec6708be5de8c5654a5434ff
2 files changed +10 -3
util/do.go
+9 -2
@@ -1,10 +1,17 @@
1 package util
2
3 -import "code.google.com/p/go.net/context"
3 +import "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
4
5 func Do(ctx context.Context, f func() error) error {
6 +
7 ch := make(chan error)
7 - go func() { ch <- f() }()
8 +
9 + go func() {
10 + select {
11 + case <-ctx.Done():
12 + case ch <- f():
13 + }
14 + }()
15 select {
16 case <-ctx.Done():
17 return ctx.Err()
util/do_test.go
+1 -1
@@ -4,7 +4,7 @@ import (
4 "errors"
5 "testing"
6
7 - "code.google.com/p/go.net/context"
7 + "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
8 )
9
10 func TestDoReturnsContextErr(t *testing.T) {