1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-29 17:36:38 +08:00

update goprocess dep

Learned proc.SetTeardown()

License: MIT
Signed-off-by: Juan Batiz-Benet <juan@benet.ai>
This commit is contained in:
Juan Batiz-Benet
2015-06-18 02:09:16 -07:00
parent c8abef059c
commit c274a3f6e1
4 changed files with 25 additions and 12 deletions

6
Godeps/Godeps.json generated
View File

@ -38,6 +38,10 @@
"ImportPath": "github.com/cheggaaa/pb",
"Rev": "d7729fd7ec1372c15b83db39834bf842bf2d69fb"
},
{
"ImportPath": "github.com/chriscool/go-sleep",
"Rev": "743ab5f1bb487edf1772bc29ca0bdf572b40785e"
},
{
"ImportPath": "github.com/codahale/hdrhistogram",
"Rev": "5fd85ec0b4e2dd5d4158d257d943f2e586d86b62"
@ -184,7 +188,7 @@
},
{
"ImportPath": "github.com/jbenet/goprocess",
"Rev": "ea63e9540cd19cb39e0e4c4442b9c27664287bb8"
"Rev": "67fe91f1081e806f1bb51051c972ac782ea46d85"
},
{
"ImportPath": "github.com/kardianos/osext",

View File

@ -115,6 +115,9 @@ type Process interface {
// It is useful to construct simple asynchronous workers, children of p.
Go(f ProcessFunc) Process
// SetTeardown sets the process's teardown to tf.
SetTeardown(tf TeardownFunc)
// Close ends the process. Close blocks until the process has completely
// shut down, and any teardown has run _exactly once_. The returned error
// is available indefinitely: calling Close twice returns the same error.

View File

@ -123,17 +123,13 @@ func TestTeardownCalledOnce(t *testing.T) {
}
}
setTeardown := func(t tree, tf TeardownFunc) {
t.Process.(*process).teardown = tf
}
setTeardown(a, onlyOnce())
setTeardown(a.c[0], onlyOnce())
setTeardown(a.c[0].c[0], onlyOnce())
setTeardown(a.c[0].c[1], onlyOnce())
setTeardown(a.c[1], onlyOnce())
setTeardown(a.c[1].c[0], onlyOnce())
setTeardown(a.c[1].c[1], onlyOnce())
a.SetTeardown(onlyOnce())
a.c[0].SetTeardown(onlyOnce())
a.c[0].c[0].SetTeardown(onlyOnce())
a.c[0].c[1].SetTeardown(onlyOnce())
a.c[1].SetTeardown(onlyOnce())
a.c[1].c[0].SetTeardown(onlyOnce())
a.c[1].c[1].SetTeardown(onlyOnce())
a.c[0].c[0].Close()
a.c[0].c[0].Close()

View File

@ -114,6 +114,16 @@ func (p *process) Go(f ProcessFunc) Process {
return child
}
// SetTeardown to assign a teardown function
func (p *process) SetTeardown(tf TeardownFunc) {
if tf == nil {
tf = nilTeardownFunc
}
p.Lock()
p.teardown = tf
p.Unlock()
}
// Close is the external close function.
// it's a wrapper around internalClose that waits on Closed()
func (p *process) Close() error {