Rename lcProcess.Run to Append, add docs
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Apr 8, 2019 at 15:57 UTC
bb4b99ef4751bc9d9e4a4d423e2adc302a63edf0
3 files changed
+15
-5
core/node/helpers.go
+13
-4
@@ -6,6 +6,7 @@ import (
6
config "github.com/ipfs/go-ipfs-config"
7
uio "github.com/ipfs/go-unixfs/io"
8
"github.com/jbenet/goprocess"
9
+ "github.com/pkg/errors"
10
"go.uber.org/fx"
11
)
12
@@ -31,15 +32,23 @@ type lcProcess struct {
32
Proc goprocess.Process
33
}
34
34
-func (lp *lcProcess) Run(f goprocess.ProcessFunc) {
35
- proc := make(chan goprocess.Process, 1)
35
+// Append wraps ProcessFunc into a goprocess, and appends it to the lifecycle
36
+func (lp *lcProcess) Append(f goprocess.ProcessFunc) {
37
+ // Hooks are guaranteed to run in sequence. If a hook fails to start, its
38
+ // OnStop won't be executed.
39
+ var proc goprocess.Process
40
+
41
lp.LC.Append(fx.Hook{
42
OnStart: func(ctx context.Context) error {
38
- proc <- lp.Proc.Go(f)
43
+ proc = lp.Proc.Go(f)
44
return nil
45
},
46
OnStop: func(ctx context.Context) error {
42
- return (<-proc).Close() // todo: respect ctx, somehow
47
+ if proc == nil { // Theoretically this shouldn't ever happen
48
+ return errors.New("lcProcess: proc was nil")
49
+ }
50
+
51
+ return proc.Close() // todo: respect ctx, somehow
52
},
53
})
54
}
core/node/ipns.go
+1
-1
@@ -66,6 +66,6 @@ func IpnsRepublisher(lc lcProcess, cfg *config.Config, namesys namesys.NameSyste
66
repub.RecordLifetime = d
67
}
68
69
- lc.Run(repub.Run)
69
+ lc.Append(repub.Run)
70
return nil
71
}
go.mod
+1
@@ -100,6 +100,7 @@ require (
100
github.com/multiformats/go-multibase v0.0.1
101
github.com/multiformats/go-multihash v0.0.1
102
github.com/opentracing/opentracing-go v1.0.2
103
+ github.com/pkg/errors v0.8.1
104
github.com/prometheus/client_golang v0.9.2
105
github.com/syndtr/goleveldb v1.0.0
106
github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc