@cryptotaxi247 / kubo / commits / bcae8392c

Update goprocess godep

License: MIT Signed-off-by: rht <rhtbot@gmail.com>

rht committed Jul 4, 2015 at 23:05 UTC bcae8392ca45c453c379a9697c474aa7880c88fe
4 files changed +45 -9
Godeps/Godeps.json
+1 -1
@@ -197,7 +197,7 @@
197 },
198 {
199 "ImportPath": "github.com/jbenet/goprocess",
200 - "Rev": "67fe91f1081e806f1bb51051c972ac782ea46d85"
200 + "Rev": "a6650d0b69f2aa0fe7c9685baf0b4d7ecc8766bf"
201 },
202 {
203 "ImportPath": "github.com/kardianos/osext",
Godeps/_workspace/src/github.com/jbenet/goprocess/context/context.go
+34 -6
@@ -10,19 +10,23 @@ import (
10 //
11 // func ProcessWithContext(ctx context.Context) goprocess.Process {
12 // p := goprocess.WithParent(goprocess.Background())
13 -// go func() {
14 -// <-ctx.Done()
15 -// p.Close()
16 -// }()
13 +// CloseAfterContext(p, ctx)
14 // return p
15 // }
16 //
17 func WithContext(ctx context.Context) goprocess.Process {
18 + p := goprocess.WithParent(goprocess.Background())
19 + CloseAfterContext(p, ctx)
20 + return p
21 +}
22 +
23 +// WithContextAndTeardown is a helper function to set teardown at initiation
24 +// of WithContext
25 +func WithContextAndTeardown(ctx context.Context, tf goprocess.TeardownFunc) goprocess.Process {
26 if ctx == nil {
27 panic("nil Context")
28 }
24 -
25 - p := goprocess.WithParent(goprocess.Background())
29 + p := goprocess.WithTeardown(tf)
30 go func() {
31 <-ctx.Done()
32 p.Close()
@@ -39,6 +43,30 @@ func WaitForContext(ctx context.Context, p goprocess.Process) {
43 p.WaitFor(WithContext(ctx))
44 }
45
46 +// CloseAfterContext schedules the process to close after the given
47 +// context is done. It is the equivalent of:
48 +//
49 +// func CloseAfterContext(p goprocess.Process, ctx context.Context) {
50 +// go func() {
51 +// <-ctx.Done()
52 +// p.Close()
53 +// }()
54 +// }
55 +//
56 +func CloseAfterContext(p goprocess.Process, ctx context.Context) {
57 + if p == nil {
58 + panic("nil Process")
59 + }
60 + if ctx == nil {
61 + panic("nil Context")
62 + }
63 +
64 + go func() {
65 + <-ctx.Done()
66 + p.Close()
67 + }()
68 +}
69 +
70 // WithProcessClosing returns a context.Context derived from ctx that
71 // is cancelled as p is Closing (after: <-p.Closing()). It is simply:
72 //
Godeps/_workspace/src/github.com/jbenet/goprocess/goprocess.go
+1 -1
@@ -114,7 +114,7 @@ type Process interface {
114 //
115 // It is useful to construct simple asynchronous workers, children of p.
116 Go(f ProcessFunc) Process
117 -
117 +
118 // SetTeardown sets the process's teardown to tf.
119 SetTeardown(tf TeardownFunc)
120
Godeps/_workspace/src/github.com/jbenet/goprocess/impl-mutex.go
+9 -1
@@ -119,8 +119,16 @@ func (p *process) SetTeardown(tf TeardownFunc) {
119 if tf == nil {
120 tf = nilTeardownFunc
121 }
122 +
123 p.Lock()
123 - p.teardown = tf
124 + if p.teardown == nil {
125 + select {
126 + case <-p.Closed():
127 + p.teardown = tf
128 + p.closeErr = tf()
129 + default:
130 + }
131 + }
132 p.Unlock()
133 }
134