summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--components.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/components.go b/components.go
index 6f59f58..7091ad1 100644
--- a/components.go
+++ b/components.go
@@ -5,8 +5,11 @@ import (
"sync"
)
+// ComponentList is a list wrapper type which handles operation modes of the program
type ComponentList[T any] []T
+// RunAsync checks components one by one and triggers the fire method in a goroutine.
+// the method will return when the waitgroup is done (all initializers are finished)
func (c ComponentList[T]) RunAsync(fire func(T) error) {
wg := sync.WaitGroup{}
for _, i := range c {
@@ -20,6 +23,8 @@ func (c ComponentList[T]) RunAsync(fire func(T) error) {
wg.Wait()
}
+// RunSync checks components one by one and fires them synchronously.
+// important when the order of init matters (for example, paths needs to go before cache)
func (c ComponentList[T]) RunSync(fire func(T) error) {
for _, i := range c {
err := fire(i)