Commit 06801a0e authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

Merge pull request #940 from jbenet/goprocess-bugfix

updated goprocess -- bugfixes
parents c5fbc667 7777a231
......@@ -207,7 +207,7 @@
},
{
"ImportPath": "github.com/jbenet/goprocess",
"Rev": "b4efc4c8775f0250710b39bfa716276ca10f85af"
"Rev": "140749d0a125caaf7c9a2893d166331e2e963a7a"
},
{
"ImportPath": "github.com/kardianos/osext",
......
......@@ -460,6 +460,44 @@ func TestCloseAfterChildren(t *testing.T) {
testStrs(t, Q, "a", "d")
}
func TestGoClosing(t *testing.T) {
var ready = make(chan struct{})
a := WithParent(Background())
a.Go(func(p Process) {
// this should be fine.
a.Go(func(p Process) {
ready <- struct{}{}
})
// set a to close. should not fully close until after this func returns.
go a.Close()
// wait until a is marked as closing
<-a.Closing()
// this should also be fine.
a.Go(func(p Process) {
select {
case <-p.Closing():
// p should be marked as closing
default:
t.Error("not marked closing when it should be.")
}
ready <- struct{}{}
})
ready <- struct{}{}
})
<-ready
<-ready
<-ready
}
func TestBackground(t *testing.T) {
// test it hangs indefinitely:
b := Background()
......
......@@ -61,6 +61,8 @@ func (p *process) AddChildNoWait(child Process) {
select {
case <-p.Closed():
panic("Process cannot add children after being closed")
case <-p.Closing():
go child.Close()
default:
}
......@@ -78,6 +80,8 @@ func (p *process) AddChild(child Process) {
select {
case <-p.Closed():
panic("Process cannot add children after being closed")
case <-p.Closing():
go child.Close()
default:
}
......@@ -88,10 +92,12 @@ func (p *process) AddChild(child Process) {
func (p *process) Go(f ProcessFunc) Process {
child := newProcess(nil)
p.AddChild(child)
waitFor := newProcess(nil)
child.WaitFor(waitFor) // prevent child from closing
// add child last, to prevent a closing parent from
// closing all of them prematurely, before running the func.
p.AddChild(child)
go func() {
f(child)
waitFor.Close() // allow child to close.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment