gum/internal/timeout/context.go
Carlos Alexandro Becker 817c4bd446
fix: lint issues (#909)
* fix: some of the lint issues

* fix: staticcheck
2025-05-30 10:34:31 -03:00

16 lines
363 B
Go

// Package timeout handles context timeouts.
package timeout
import (
"context"
"time"
)
// Context setup a new context that times out if the given timeout is > 0.
func Context(timeout time.Duration) (context.Context, context.CancelFunc) {
ctx := context.Background()
if timeout == 0 {
return ctx, func() {}
}
return context.WithTimeout(ctx, timeout)
}