1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-12-18 00:47:05 +08:00
Files
kubo/core/node/helpers.go
Andrew Gillis 90b73d2ad2 refactor: remove goprocess (#10872)
* refactor: remove goprocess

The `goprocess` package is no longer needed. It can be replaces by modern `context` and `context.AfterFunc`.

* mod tidy

* log unmount errors on shutdown

* Do not log non-mounted errors on shutdown

* Use WaitGroup associated with IPFS node to wait for services to whutdown

* Prefer explicit Close to context.ArterFunc

* Do not use node-level WaitGroup

* Unmount for non-supported platforms

* fix return values

* test: daemon shuts down gracefully

make sure ongoing operations dont block shutdown

* test(cli): add TestFUSE

* test: smarter RequiresFUSE

opportunistically run FUSE tests if env has fusermount
and TEST_FUSE was not explicitly set

* docs: changelog

---------

Co-authored-by: gammazero <gammazero@users.noreply.github.com>
Co-authored-by: Marcin Rataj <lidel@lidel.org>
2025-08-06 00:33:45 +02:00

57 lines
1.0 KiB
Go

package node
import (
"context"
"errors"
"go.uber.org/fx"
)
type lcStartStop struct {
fx.In
LC fx.Lifecycle
}
// Append wraps a function into a fx.Hook and appends it to the fx.Lifecycle.
func (lcss *lcStartStop) Append(f func() func()) {
// Hooks are guaranteed to run in sequence. If a hook fails to start, its
// OnStop won't be executed.
var stopFunc func()
lcss.LC.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
if ctx.Err() != nil {
return nil
}
stopFunc = f()
return nil
},
OnStop: func(ctx context.Context) error {
if ctx.Err() != nil {
return nil
}
if stopFunc == nil { // Theoretically this shouldn't ever happen
return errors.New("lcStatStop: stopFunc was nil")
}
stopFunc()
return nil
},
})
}
func maybeProvide(opt interface{}, enable bool) fx.Option {
if enable {
return fx.Provide(opt)
}
return fx.Options()
}
// nolint unused
func maybeInvoke(opt interface{}, enable bool) fx.Option {
if enable {
return fx.Invoke(opt)
}
return fx.Options()
}