vend with

This commit is contained in:
bel
2026-06-27 16:44:47 -06:00
parent 48c3474c15
commit a9f78655c3
20 changed files with 1068 additions and 3 deletions
+24
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)
}