lotus/node/modules/helpers/helpers.go
Andrew Jackson (Ajax) c1edae62ad gen fix
2023-11-15 13:06:51 +01:00

25 lines
535 B
Go

package helpers
import (
"context"
"go.uber.org/fx"
)
// MetricsCtx is a context wrapper with metrics
type MetricsCtx context.Context
// LifecycleCtx creates a context which will be cancelled 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
}