Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
bcae8392
提交
bcae8392
authored
7月 04, 2015
作者:
rht
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update goprocess godep
License: MIT Signed-off-by:
rht
<
rhtbot@gmail.com
>
上级
007a12e7
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
45 行增加
和
9 行删除
+45
-9
Godeps.json
Godeps/Godeps.json
+1
-1
context.go
...kspace/src/github.com/jbenet/goprocess/context/context.go
+34
-6
goprocess.go
...s/_workspace/src/github.com/jbenet/goprocess/goprocess.go
+1
-1
impl-mutex.go
.../_workspace/src/github.com/jbenet/goprocess/impl-mutex.go
+9
-1
没有找到文件。
Godeps/Godeps.json
浏览文件 @
bcae8392
...
...
@@ -197,7 +197,7 @@
},
{
"ImportPath"
:
"github.com/jbenet/goprocess"
,
"Rev"
:
"
67fe91f1081e806f1bb51051c972ac782ea46d85
"
"Rev"
:
"
a6650d0b69f2aa0fe7c9685baf0b4d7ecc8766bf
"
},
{
"ImportPath"
:
"github.com/kardianos/osext"
,
...
...
Godeps/_workspace/src/github.com/jbenet/goprocess/context/context.go
浏览文件 @
bcae8392
...
...
@@ -10,19 +10,23 @@ import (
//
// func ProcessWithContext(ctx context.Context) goprocess.Process {
// p := goprocess.WithParent(goprocess.Background())
// go func() {
// <-ctx.Done()
// p.Close()
// }()
// CloseAfterContext(p, ctx)
// return p
// }
//
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
{
panic
(
"nil Context"
)
}
p
:=
goprocess
.
WithParent
(
goprocess
.
Background
())
p
:=
goprocess
.
WithTeardown
(
tf
)
go
func
()
{
<-
ctx
.
Done
()
p
.
Close
()
...
...
@@ -39,6 +43,30 @@ func WaitForContext(ctx context.Context, p goprocess.Process) {
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
// is cancelled as p is Closing (after: <-p.Closing()). It is simply:
//
...
...
Godeps/_workspace/src/github.com/jbenet/goprocess/goprocess.go
浏览文件 @
bcae8392
...
...
@@ -114,7 +114,7 @@ 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
)
...
...
Godeps/_workspace/src/github.com/jbenet/goprocess/impl-mutex.go
浏览文件 @
bcae8392
...
...
@@ -119,8 +119,16 @@ func (p *process) SetTeardown(tf TeardownFunc) {
if
tf
==
nil
{
tf
=
nilTeardownFunc
}
p
.
Lock
()
p
.
teardown
=
tf
if
p
.
teardown
==
nil
{
select
{
case
<-
p
.
Closed
()
:
p
.
teardown
=
tf
p
.
closeErr
=
tf
()
default
:
}
}
p
.
Unlock
()
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论