mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-29 17:36:38 +08:00
updated goprocess (SetTeardown fix)
License: MIT Signed-off-by: Juan Batiz-Benet <juan@benet.ai>
This commit is contained in:
2
Godeps/Godeps.json
generated
2
Godeps/Godeps.json
generated
@ -204,7 +204,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/jbenet/goprocess",
|
"ImportPath": "github.com/jbenet/goprocess",
|
||||||
"Rev": "788dcf5ca3517f243d276394545ca6b3b4ac32d5"
|
"Rev": "4562d0c5780b8f060df2b84a8945bb8678bfc023"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/kardianos/osext",
|
"ImportPath": "github.com/kardianos/osext",
|
||||||
|
2
Godeps/_workspace/src/github.com/jbenet/goprocess/goprocess.go
generated
vendored
2
Godeps/_workspace/src/github.com/jbenet/goprocess/goprocess.go
generated
vendored
@ -145,8 +145,6 @@ type Process interface {
|
|||||||
// lifecycle of a Process.
|
// lifecycle of a Process.
|
||||||
type TeardownFunc func() error
|
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,
|
// 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
|
// which spawns a ProcessFunc in its own goroutine, and returns a corresponding
|
||||||
// Process object.
|
// Process object.
|
||||||
|
2
Godeps/_workspace/src/github.com/jbenet/goprocess/goprocess_test.go
generated
vendored
2
Godeps/_workspace/src/github.com/jbenet/goprocess/goprocess_test.go
generated
vendored
@ -300,13 +300,11 @@ func TestAddChild(t *testing.T) {
|
|||||||
testNone(t, Q)
|
testNone(t, Q)
|
||||||
|
|
||||||
go b.Close()
|
go b.Close()
|
||||||
testNone(t, Q)
|
|
||||||
d.Close()
|
d.Close()
|
||||||
testStrs(t, Q, "b", "d")
|
testStrs(t, Q, "b", "d")
|
||||||
testStrs(t, Q, "b", "d")
|
testStrs(t, Q, "b", "d")
|
||||||
|
|
||||||
go a.Close()
|
go a.Close()
|
||||||
testNone(t, Q)
|
|
||||||
c.Close()
|
c.Close()
|
||||||
testStrs(t, Q, "a", "c")
|
testStrs(t, Q, "a", "c")
|
||||||
testStrs(t, Q, "a", "c")
|
testStrs(t, Q, "a", "c")
|
||||||
|
28
Godeps/_workspace/src/github.com/jbenet/goprocess/impl-mutex.go
generated
vendored
28
Godeps/_workspace/src/github.com/jbenet/goprocess/impl-mutex.go
generated
vendored
@ -25,10 +25,6 @@ type process struct {
|
|||||||
// **after** entering <-Closing(), and
|
// **after** entering <-Closing(), and
|
||||||
// **before** <-Closed().
|
// **before** <-Closed().
|
||||||
func newProcess(tf TeardownFunc) *process {
|
func newProcess(tf TeardownFunc) *process {
|
||||||
if tf == nil {
|
|
||||||
tf = nilTeardownFunc
|
|
||||||
}
|
|
||||||
|
|
||||||
return &process{
|
return &process{
|
||||||
teardown: tf,
|
teardown: tf,
|
||||||
closed: make(chan struct{}),
|
closed: make(chan struct{}),
|
||||||
@ -123,17 +119,19 @@ func (p *process) Go(f ProcessFunc) Process {
|
|||||||
// SetTeardown to assign a teardown function
|
// SetTeardown to assign a teardown function
|
||||||
func (p *process) SetTeardown(tf TeardownFunc) {
|
func (p *process) SetTeardown(tf TeardownFunc) {
|
||||||
if tf == nil {
|
if tf == nil {
|
||||||
tf = nilTeardownFunc
|
panic("cannot set nil TeardownFunc")
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Lock()
|
p.Lock()
|
||||||
if p.teardown == nil {
|
if p.teardown != nil {
|
||||||
select {
|
panic("cannot SetTeardown twice")
|
||||||
case <-p.Closed():
|
}
|
||||||
p.teardown = tf
|
|
||||||
p.closeErr = tf()
|
p.teardown = tf
|
||||||
default:
|
select {
|
||||||
}
|
case <-p.Closed():
|
||||||
|
p.closeErr = tf()
|
||||||
|
default:
|
||||||
}
|
}
|
||||||
p.Unlock()
|
p.Unlock()
|
||||||
}
|
}
|
||||||
@ -196,8 +194,10 @@ func (p *process) doClose() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p.closeErr = p.teardown() // actually run the close logic (ok safe to teardown)
|
if p.teardown != nil {
|
||||||
close(p.closed) // signal that we're shut down (Closed)
|
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 remove all the parents from the process links. optimization.
|
||||||
go func(waiters []*processLink) {
|
go func(waiters []*processLink) {
|
||||||
|
Reference in New Issue
Block a user