stead from pg

This commit is contained in:
Bel LaPointe
2026-03-09 09:02:16 -06:00
parent 4bf673461e
commit cc18763944
9 changed files with 318 additions and 0 deletions

24
ctx.go Normal file
View File

@@ -0,0 +1,24 @@
package with
import (
"context"
"os/signal"
"syscall"
"time"
)
func Context(foo func(context.Context) error) error {
ctx, can := signal.NotifyContext(context.Background(), syscall.SIGINT)
defer can()
if err := foo(ctx); err != nil && ctx.Err() == nil {
return err
}
return nil
}
func Timeout(ctx context.Context, d time.Duration, foo func(context.Context) error) error {
ctx, can := context.WithTimeout(ctx, d)
defer can()
return foo(ctx)
}