updated goprocess (SetTeardown fix)
License: MIT Signed-off-by: Juan Batiz-Benet <juan@benet.ai>
Juan Batiz-Benet committed
Jul 29, 2015 at 01:18 UTC
7a41dcb620f67b047d9ae167e64a593b1dcb4601
4 files changed
+15
-19
Godeps/Godeps.json
+1
-1
@@ -204,7 +204,7 @@
204
},
205
{
206
"ImportPath": "github.com/jbenet/goprocess",
207
- "Rev": "788dcf5ca3517f243d276394545ca6b3b4ac32d5"
207
+ "Rev": "4562d0c5780b8f060df2b84a8945bb8678bfc023"
208
},
209
{
210
"ImportPath": "github.com/kardianos/osext",
Godeps/_workspace/src/github.com/jbenet/goprocess/goprocess.go
-2
@@ -145,8 +145,6 @@ type Process interface {
145
// lifecycle of a Process.
146
type TeardownFunc func() error
147
148
-var nilTeardownFunc = func() error { return nil }
149
-
148
// ProcessFunc is a function that takes a process. Its main use case is goprocess.Go,
149
// which spawns a ProcessFunc in its own goroutine, and returns a corresponding
150
// Process object.
Godeps/_workspace/src/github.com/jbenet/goprocess/goprocess_test.go
-2
@@ -300,13 +300,11 @@ func TestAddChild(t *testing.T) {
300
testNone(t, Q)
301
302
go b.Close()
303
- testNone(t, Q)
303
d.Close()
304
testStrs(t, Q, "b", "d")
305
testStrs(t, Q, "b", "d")
306
307
go a.Close()
309
- testNone(t, Q)
308
c.Close()
309
testStrs(t, Q, "a", "c")
310
testStrs(t, Q, "a", "c")
Godeps/_workspace/src/github.com/jbenet/goprocess/impl-mutex.go
+14
-14
@@ -25,10 +25,6 @@ type process struct {
25
// **after** entering <-Closing(), and
26
// **before** <-Closed().
27
func newProcess(tf TeardownFunc) *process {
28
- if tf == nil {
29
- tf = nilTeardownFunc
30
- }
31
-
28
return &process{
29
teardown: tf,
30
closed: make(chan struct{}),
@@ -123,17 +119,19 @@ func (p *process) Go(f ProcessFunc) Process {
119
// SetTeardown to assign a teardown function
120
func (p *process) SetTeardown(tf TeardownFunc) {
121
if tf == nil {
126
- tf = nilTeardownFunc
122
+ panic("cannot set nil TeardownFunc")
123
}
124
125
p.Lock()
130
- if p.teardown == nil {
131
- select {
132
- case <-p.Closed():
133
- p.teardown = tf
134
- p.closeErr = tf()
135
- default:
136
- }
126
+ if p.teardown != nil {
127
+ panic("cannot SetTeardown twice")
128
+ }
129
+
130
+ p.teardown = tf
131
+ select {
132
+ case <-p.Closed():
133
+ p.closeErr = tf()
134
+ default:
135
}
136
p.Unlock()
137
}
@@ -196,8 +194,10 @@ func (p *process) doClose() {
194
}
195
}
196
199
- p.closeErr = p.teardown() // actually run the close logic (ok safe to teardown)
200
- close(p.closed) // signal that we're shut down (Closed)
197
+ if p.teardown != nil {
198
+ p.closeErr = p.teardown() // actually run the close logic (ok safe to teardown)
199
+ }
200
+ close(p.closed) // signal that we're shut down (Closed)
201
202
// go remove all the parents from the process links. optimization.
203
go func(waiters []*processLink) {