add basic scheduler
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-01-06 22:24:56 +01:00
parent be6403105c
commit ed2e15a3dd
12 changed files with 109 additions and 2 deletions

View File

@@ -0,0 +1,25 @@
package utilities
import (
"fmt"
"sync"
)
func Singleton[T any](init func() (T, error)) func() T {
var (
once sync.Once
t T
)
return func() T {
once.Do(func() {
var err error
t, err = init()
if err != nil {
panic(fmt.Sprintf("creating %T failed: %s", t, err))
}
})
return t
}
}