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

@ -7,7 +7,7 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/status"
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient"
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/php"
"github.com/FAU-CDI/wisski-distillery/pkg/lazy"
"github.com/tkw1536/pkglib/lifetime"
"golang.org/x/sync/errgroup"
)
@ -18,7 +18,7 @@ type Info struct {
Fetchers []ingredient.WissKIFetcher
}
Analytics *lazy.PoolAnalytics
Analytics *lifetime.Analytics
}
var (

View file

@ -9,7 +9,7 @@ import (
// Ingredients represent a part of a WissKI instance.
// An Ingredient should be implemented as a pointer to a struct.
// Every ingredient must embed [Base] and should be initialized using [Init] inside a [lazy.Pool].
// Every ingredient must embed [Base] and should be initialized using [Init] inside a [lifetime.Lifetime].
//
// By convention these are defined within their corresponding subpackage.
// This subpackage also contains all required resources.
@ -35,7 +35,7 @@ func (cb *Base) getBase() *Base {
}
// Init initializes a new Ingredient.
// Init is only intended to be used within a lazy.Pool[Ingredient,*Liquid].
// Init is only intended to be used within a lifetime.Lifetime[Ingredient,*Liquid].
func Init(ingredient Ingredient, liquid *liquid.Liquid) Ingredient {
base := ingredient.getBase() // pointer to a struct
base.Liquid = liquid

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

View file

@ -18,7 +18,7 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/php/users"
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/reserve"
"github.com/FAU-CDI/wisski-distillery/internal/wisski/liquid"
"github.com/FAU-CDI/wisski-distillery/pkg/lazy"
"github.com/tkw1536/pkglib/lifetime"
)
// WissKI represents a single WissKI Instance.
@ -26,8 +26,8 @@ import (
type WissKI struct {
liquid.Liquid
poolInit sync.Once
pool lazy.Pool[ingredient.Ingredient, *liquid.Liquid]
lifetimeInit sync.Once
lifetime lifetime.Lifetime[ingredient.Ingredient, *liquid.Liquid]
}
//
@ -110,7 +110,7 @@ func (wisski *WissKI) allIngredients() []initFunc {
// info
manual(func(info *info.Info) {
info.Analytics = &wisski.pool.Analytics
info.Analytics = &wisski.lifetime.Analytics
}),
auto[*barrel.LastRebuildFetcher],
auto[*barrel.RunningFetcher],