Migrate pkg/lazy => pkglib/{lazy,lifetime}

This commit is contained in:
Tom Wiesing 2023-02-26 10:00:47 +01:00
parent c3ca8e2974
commit 5e89fadeeb
No known key found for this signature in database
21 changed files with 54 additions and 612 deletions

View file

@ -3,8 +3,8 @@ package wisski
import (
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient"
"github.com/FAU-CDI/wisski-distillery/internal/wisski/liquid"
"github.com/FAU-CDI/wisski-distillery/pkg/lazy"
"github.com/tkw1536/pkglib/collection"
"github.com/tkw1536/pkglib/lifetime"
)
//
@ -12,9 +12,9 @@ import (
//
func (wisski *WissKI) init() {
wisski.poolInit.Do(func() {
wisski.pool.Init = ingredient.Init
lazy.RegisterPoolGroup[ingredient.WissKIFetcher](&wisski.pool)
wisski.lifetimeInit.Do(func() {
wisski.lifetime.Init = ingredient.Init
lifetime.RegisterGroup[ingredient.WissKIFetcher](&wisski.lifetime)
})
}
@ -25,13 +25,13 @@ func (wisski *WissKI) init() {
// manual initializes a component from the provided distillery.
func manual[I ingredient.Ingredient](init func(ingredient I)) initFunc {
return func(context ctx) ingredient.Ingredient {
return lazy.Make(context, init)
return lifetime.Make(context, init)
}
}
// use is like r, but does not provided additional initialization
func auto[I ingredient.Ingredient](context ctx) ingredient.Ingredient {
return lazy.Make[ingredient.Ingredient, I](context, nil)
return lifetime.Make[ingredient.Ingredient, I](context, nil)
}
// register returns all components of the distillery
@ -45,7 +45,7 @@ func (wisski *WissKI) register(context ctx) []ingredient.Ingredient {
}
// ctx is a context for component initialization
type ctx = *lazy.PoolContext[ingredient.Ingredient]
type ctx = *lifetime.InjectorContext[ingredient.Ingredient]
//
// ==== export ====
@ -54,13 +54,13 @@ type ctx = *lazy.PoolContext[ingredient.Ingredient]
// export is a convenience function to export a single component
func export[I ingredient.Ingredient](wisski *WissKI) I {
wisski.init()
return lazy.ExportComponent[ingredient.Ingredient, *liquid.Liquid, I](&wisski.pool, &wisski.Liquid, wisski.register)
return lifetime.ExportComponent[ingredient.Ingredient, *liquid.Liquid, I](&wisski.lifetime, &wisski.Liquid, wisski.register)
}
//lint:ignore U1000 for future use
func exportAll[I ingredient.Ingredient](wisski *WissKI) []I {
wisski.init()
return lazy.ExportComponents[ingredient.Ingredient, *liquid.Liquid, I](&wisski.pool, &wisski.Liquid, wisski.register)
return lifetime.ExportComponents[ingredient.Ingredient, *liquid.Liquid, I](&wisski.lifetime, &wisski.Liquid, wisski.register)
}
type initFunc = func(context ctx) ingredient.Ingredient