add close

This commit is contained in:
yanghao05
2023-06-01 11:02:10 +08:00
parent 690df80c39
commit d28d9649ed
6 changed files with 20 additions and 4 deletions

View File

@@ -11,6 +11,7 @@ import (
var Container *dig.Container = dig.New()
var Cancel context.CancelFunc
var closeable []func()
func init() {
if err := Container.Provide(func() context.Context {
@@ -20,6 +21,18 @@ func init() {
}); err != nil {
log.Fatal(err)
}
closeable = make([]func(), 0)
}
func AddCloseAble(c func()) {
closeable = append(closeable, c)
}
func Close() {
for _, c := range closeable {
c()
}
}
type ProviderContainer struct {