1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-05-21 17:08:13 +08:00
Files
kubo/core/node/helpers/helpers.go
Andrew Gillis 53792003bd collection of typo fixes (#10647)
(cherry picked from commit 942542111447bbc076c9d20bc11ddb17fb410ea0)
2025-01-13 18:55:10 +01:00

25 lines
487 B
Go

package helpers
import (
"context"
"go.uber.org/fx"
)
type MetricsCtx context.Context
// LifecycleCtx creates a context which will be canceled when lifecycle stops
//
// This is a hack which we need because most of our services use contexts in a
// wrong way
func LifecycleCtx(mctx MetricsCtx, lc fx.Lifecycle) context.Context {
ctx, cancel := context.WithCancel(mctx)
lc.Append(fx.Hook{
OnStop: func(_ context.Context) error {
cancel()
return nil
},
})
return ctx
}