提交 bb4b99ef 作者: Łukasz Magiera 提交者: Steven Allen

Rename lcProcess.Run to Append, add docs

License: MIT
Signed-off-by: 's avatarŁukasz Magiera <magik6k@gmail.com>
上级 803512e4
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
config "github.com/ipfs/go-ipfs-config" config "github.com/ipfs/go-ipfs-config"
uio "github.com/ipfs/go-unixfs/io" uio "github.com/ipfs/go-unixfs/io"
"github.com/jbenet/goprocess" "github.com/jbenet/goprocess"
"github.com/pkg/errors"
"go.uber.org/fx" "go.uber.org/fx"
) )
...@@ -31,15 +32,23 @@ type lcProcess struct { ...@@ -31,15 +32,23 @@ type lcProcess struct {
Proc goprocess.Process Proc goprocess.Process
} }
func (lp *lcProcess) Run(f goprocess.ProcessFunc) { // Append wraps ProcessFunc into a goprocess, and appends it to the lifecycle
proc := make(chan goprocess.Process, 1) func (lp *lcProcess) Append(f goprocess.ProcessFunc) {
// Hooks are guaranteed to run in sequence. If a hook fails to start, its
// OnStop won't be executed.
var proc goprocess.Process
lp.LC.Append(fx.Hook{ lp.LC.Append(fx.Hook{
OnStart: func(ctx context.Context) error { OnStart: func(ctx context.Context) error {
proc <- lp.Proc.Go(f) proc = lp.Proc.Go(f)
return nil return nil
}, },
OnStop: func(ctx context.Context) error { OnStop: func(ctx context.Context) error {
return (<-proc).Close() // todo: respect ctx, somehow if proc == nil { // Theoretically this shouldn't ever happen
return errors.New("lcProcess: proc was nil")
}
return proc.Close() // todo: respect ctx, somehow
}, },
}) })
} }
......
...@@ -66,6 +66,6 @@ func IpnsRepublisher(lc lcProcess, cfg *config.Config, namesys namesys.NameSyste ...@@ -66,6 +66,6 @@ func IpnsRepublisher(lc lcProcess, cfg *config.Config, namesys namesys.NameSyste
repub.RecordLifetime = d repub.RecordLifetime = d
} }
lc.Run(repub.Run) lc.Append(repub.Run)
return nil return nil
} }
...@@ -100,6 +100,7 @@ require ( ...@@ -100,6 +100,7 @@ require (
github.com/multiformats/go-multibase v0.0.1 github.com/multiformats/go-multibase v0.0.1
github.com/multiformats/go-multihash v0.0.1 github.com/multiformats/go-multihash v0.0.1
github.com/opentracing/opentracing-go v1.0.2 github.com/opentracing/opentracing-go v1.0.2
github.com/pkg/errors v0.8.1
github.com/prometheus/client_golang v0.9.2 github.com/prometheus/client_golang v0.9.2
github.com/syndtr/goleveldb v1.0.0 github.com/syndtr/goleveldb v1.0.0
github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论