diff options
| author | ewy <ewy0@protonmail.com> | 2026-05-02 17:07:13 +0200 |
|---|---|---|
| committer | ewy <ewy0@protonmail.com> | 2026-05-02 17:07:13 +0200 |
| commit | 1c681ad4149f994a2a8caf21133747b9348002c6 (patch) | |
| tree | 2fee367772f07dbc80fa1b036535abd8aab8bf40 /components.go | |
| parent | f78ac099102715281f27492142ebf0fe6004d0a1 (diff) | |
add a little abstraction to the main branches
Diffstat (limited to 'components.go')
| -rw-r--r-- | components.go | 30 |
1 files changed, 30 insertions, 0 deletions
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) + } + } +} |
