mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-26 15:42:21 +08:00
Update goprocess godep
License: MIT Signed-off-by: rht <rhtbot@gmail.com>
This commit is contained in:
2
Godeps/Godeps.json
generated
2
Godeps/Godeps.json
generated
@ -197,7 +197,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/jbenet/goprocess",
|
"ImportPath": "github.com/jbenet/goprocess",
|
||||||
"Rev": "67fe91f1081e806f1bb51051c972ac782ea46d85"
|
"Rev": "a6650d0b69f2aa0fe7c9685baf0b4d7ecc8766bf"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/kardianos/osext",
|
"ImportPath": "github.com/kardianos/osext",
|
||||||
|
40
Godeps/_workspace/src/github.com/jbenet/goprocess/context/context.go
generated
vendored
40
Godeps/_workspace/src/github.com/jbenet/goprocess/context/context.go
generated
vendored
@ -10,19 +10,23 @@ import (
|
|||||||
//
|
//
|
||||||
// func ProcessWithContext(ctx context.Context) goprocess.Process {
|
// func ProcessWithContext(ctx context.Context) goprocess.Process {
|
||||||
// p := goprocess.WithParent(goprocess.Background())
|
// p := goprocess.WithParent(goprocess.Background())
|
||||||
// go func() {
|
// CloseAfterContext(p, ctx)
|
||||||
// <-ctx.Done()
|
|
||||||
// p.Close()
|
|
||||||
// }()
|
|
||||||
// return p
|
// return p
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
func WithContext(ctx context.Context) goprocess.Process {
|
func WithContext(ctx context.Context) goprocess.Process {
|
||||||
|
p := goprocess.WithParent(goprocess.Background())
|
||||||
|
CloseAfterContext(p, ctx)
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithContextAndTeardown is a helper function to set teardown at initiation
|
||||||
|
// of WithContext
|
||||||
|
func WithContextAndTeardown(ctx context.Context, tf goprocess.TeardownFunc) goprocess.Process {
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
panic("nil Context")
|
panic("nil Context")
|
||||||
}
|
}
|
||||||
|
p := goprocess.WithTeardown(tf)
|
||||||
p := goprocess.WithParent(goprocess.Background())
|
|
||||||
go func() {
|
go func() {
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
p.Close()
|
p.Close()
|
||||||
@ -39,6 +43,30 @@ func WaitForContext(ctx context.Context, p goprocess.Process) {
|
|||||||
p.WaitFor(WithContext(ctx))
|
p.WaitFor(WithContext(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CloseAfterContext schedules the process to close after the given
|
||||||
|
// context is done. It is the equivalent of:
|
||||||
|
//
|
||||||
|
// func CloseAfterContext(p goprocess.Process, ctx context.Context) {
|
||||||
|
// go func() {
|
||||||
|
// <-ctx.Done()
|
||||||
|
// p.Close()
|
||||||
|
// }()
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
func CloseAfterContext(p goprocess.Process, ctx context.Context) {
|
||||||
|
if p == nil {
|
||||||
|
panic("nil Process")
|
||||||
|
}
|
||||||
|
if ctx == nil {
|
||||||
|
panic("nil Context")
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
<-ctx.Done()
|
||||||
|
p.Close()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
// WithProcessClosing returns a context.Context derived from ctx that
|
// WithProcessClosing returns a context.Context derived from ctx that
|
||||||
// is cancelled as p is Closing (after: <-p.Closing()). It is simply:
|
// is cancelled as p is Closing (after: <-p.Closing()). It is simply:
|
||||||
//
|
//
|
||||||
|
8
Godeps/_workspace/src/github.com/jbenet/goprocess/impl-mutex.go
generated
vendored
8
Godeps/_workspace/src/github.com/jbenet/goprocess/impl-mutex.go
generated
vendored
@ -119,8 +119,16 @@ func (p *process) SetTeardown(tf TeardownFunc) {
|
|||||||
if tf == nil {
|
if tf == nil {
|
||||||
tf = nilTeardownFunc
|
tf = nilTeardownFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Lock()
|
p.Lock()
|
||||||
|
if p.teardown == nil {
|
||||||
|
select {
|
||||||
|
case <-p.Closed():
|
||||||
p.teardown = tf
|
p.teardown = tf
|
||||||
|
p.closeErr = tf()
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
p.Unlock()
|
p.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user