mirror of
https://github.com/charmbracelet/gum
synced 2026-03-14 21:55:45 +01:00
16 lines
363 B
Go
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)
|
|
}
|