From 1c681ad4149f994a2a8caf21133747b9348002c6 Mon Sep 17 00:00:00 2001 From: ewy Date: Sat, 2 May 2026 17:07:13 +0200 Subject: add a little abstraction to the main branches --- components.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 components.go (limited to 'components.go') diff --git a/components.go b/components.go new file mode 100644 index 0000000..6f59f58 --- /dev/null +++ b/components.go @@ -0,0 +1,30 @@ +package main + +import ( + "github.com/ewy1/pik/spool" + "sync" +) + +type ComponentList[T any] []T + +func (c ComponentList[T]) RunAsync(fire func(T) error) { + wg := sync.WaitGroup{} + for _, i := range c { + wg.Go(func() { + err := fire(i) + if err != nil { + _, _ = spool.Warn("%v\n", err) + } + }) + } + wg.Wait() +} + +func (c ComponentList[T]) RunSync(fire func(T) error) { + for _, i := range c { + err := fire(i) + if err != nil { + _, _ = spool.Warn("%v\n", err) + } + } +} -- cgit v1.3.1