Import libp2p modules
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
This commit is contained in:
committed by
Jakub Sztandera
parent
795621ed27
commit
63627e863e
@@ -0,0 +1,25 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user