From 7a41dcb620f67b047d9ae167e64a593b1dcb4601 Mon Sep 17 00:00:00 2001 From: Juan Batiz-Benet Date: Wed, 29 Jul 2015 01:18:04 -0700 Subject: [PATCH] updated goprocess (SetTeardown fix) License: MIT Signed-off-by: Juan Batiz-Benet --- Godeps/Godeps.json | 2 +- .../github.com/jbenet/goprocess/goprocess.go | 2 -- .../jbenet/goprocess/goprocess_test.go | 2 -- .../github.com/jbenet/goprocess/impl-mutex.go | 28 +++++++++---------- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 1797c4f88..d1663a336 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -204,7 +204,7 @@ }, { "ImportPath": "github.com/jbenet/goprocess", - "Rev": "788dcf5ca3517f243d276394545ca6b3b4ac32d5" + "Rev": "4562d0c5780b8f060df2b84a8945bb8678bfc023" }, { "ImportPath": "github.com/kardianos/osext", diff --git a/Godeps/_workspace/src/github.com/jbenet/goprocess/goprocess.go b/Godeps/_workspace/src/github.com/jbenet/goprocess/goprocess.go index 17cb37799..b027d8214 100644 --- a/Godeps/_workspace/src/github.com/jbenet/goprocess/goprocess.go +++ b/Godeps/_workspace/src/github.com/jbenet/goprocess/goprocess.go @@ -145,8 +145,6 @@ type Process interface { // lifecycle of a Process. type TeardownFunc func() error -var nilTeardownFunc = func() error { return nil } - // ProcessFunc is a function that takes a process. Its main use case is goprocess.Go, // which spawns a ProcessFunc in its own goroutine, and returns a corresponding // Process object. diff --git a/Godeps/_workspace/src/github.com/jbenet/goprocess/goprocess_test.go b/Godeps/_workspace/src/github.com/jbenet/goprocess/goprocess_test.go index 81c195843..3a16de7e6 100644 --- a/Godeps/_workspace/src/github.com/jbenet/goprocess/goprocess_test.go +++ b/Godeps/_workspace/src/github.com/jbenet/goprocess/goprocess_test.go @@ -300,13 +300,11 @@ func TestAddChild(t *testing.T) { testNone(t, Q) go b.Close() - testNone(t, Q) d.Close() testStrs(t, Q, "b", "d") testStrs(t, Q, "b", "d") go a.Close() - testNone(t, Q) c.Close() testStrs(t, Q, "a", "c") testStrs(t, Q, "a", "c") diff --git a/Godeps/_workspace/src/github.com/jbenet/goprocess/impl-mutex.go b/Godeps/_workspace/src/github.com/jbenet/goprocess/impl-mutex.go index c6acc4f41..a67deea75 100644 --- a/Godeps/_workspace/src/github.com/jbenet/goprocess/impl-mutex.go +++ b/Godeps/_workspace/src/github.com/jbenet/goprocess/impl-mutex.go @@ -25,10 +25,6 @@ type process struct { // **after** entering <-Closing(), and // **before** <-Closed(). func newProcess(tf TeardownFunc) *process { - if tf == nil { - tf = nilTeardownFunc - } - return &process{ teardown: tf, closed: make(chan struct{}), @@ -123,17 +119,19 @@ func (p *process) Go(f ProcessFunc) Process { // SetTeardown to assign a teardown function func (p *process) SetTeardown(tf TeardownFunc) { if tf == nil { - tf = nilTeardownFunc + panic("cannot set nil TeardownFunc") } p.Lock() - if p.teardown == nil { - select { - case <-p.Closed(): - p.teardown = tf - p.closeErr = tf() - default: - } + if p.teardown != nil { + panic("cannot SetTeardown twice") + } + + p.teardown = tf + select { + case <-p.Closed(): + p.closeErr = tf() + default: } p.Unlock() } @@ -196,8 +194,10 @@ func (p *process) doClose() { } } - p.closeErr = p.teardown() // actually run the close logic (ok safe to teardown) - close(p.closed) // signal that we're shut down (Closed) + if p.teardown != nil { + p.closeErr = p.teardown() // actually run the close logic (ok safe to teardown) + } + close(p.closed) // signal that we're shut down (Closed) // go remove all the parents from the process links. optimization. go func(waiters []*processLink) {