mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 18:37:45 +08:00
Rename lcProcess.Run to Append, add docs
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
parent
803512e46c
commit
bb4b99ef47
@ -6,6 +6,7 @@ import (
|
||||
config "github.com/ipfs/go-ipfs-config"
|
||||
uio "github.com/ipfs/go-unixfs/io"
|
||||
"github.com/jbenet/goprocess"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
@ -31,15 +32,23 @@ type lcProcess struct {
|
||||
Proc goprocess.Process
|
||||
}
|
||||
|
||||
func (lp *lcProcess) Run(f goprocess.ProcessFunc) {
|
||||
proc := make(chan goprocess.Process, 1)
|
||||
// Append wraps ProcessFunc into a goprocess, and appends it to the lifecycle
|
||||
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{
|
||||
OnStart: func(ctx context.Context) error {
|
||||
proc <- lp.Proc.Go(f)
|
||||
proc = lp.Proc.Go(f)
|
||||
return nil
|
||||
},
|
||||
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
|
||||
repub.RecordLifetime = d
|
||||
}
|
||||
|
||||
lc.Run(repub.Run)
|
||||
lc.Append(repub.Run)
|
||||
return nil
|
||||
}
|
||||
|
||||
1
go.mod
1
go.mod
@ -100,6 +100,7 @@ require (
|
||||
github.com/multiformats/go-multibase v0.0.1
|
||||
github.com/multiformats/go-multihash v0.0.1
|
||||
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/syndtr/goleveldb v1.0.0
|
||||
github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc
|
||||
|
||||
Loading…
Reference in New Issue
Block a user