mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 18:37:45 +08:00
Some checks failed
CodeQL / codeql (push) Has been cancelled
Docker Build / docker-build (push) Has been cancelled
Gateway Conformance / gateway-conformance (push) Has been cancelled
Gateway Conformance / gateway-conformance-libp2p-experiment (push) Has been cancelled
Go Build / go-build (push) Has been cancelled
Go Check / go-check (push) Has been cancelled
Go Lint / go-lint (push) Has been cancelled
Go Test / go-test (push) Has been cancelled
Interop / interop-prep (push) Has been cancelled
Sharness / sharness-test (push) Has been cancelled
Interop / helia-interop (push) Has been cancelled
Interop / ipfs-webui (push) Has been cancelled
25 lines
487 B
Go
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
|
|
}
|