MCPcopy Create free account
hub / github.com/DBCDK/morph / ContextWithConditionalTimeout

Function ContextWithConditionalTimeout

utils/context.go:9–22  ·  view source on GitHub ↗

Create a context with a timeout, but only if the timeout is longer than 0

(parent context.Context, timeout int)

Source from the content-addressed store, hash-verified

7
8// Create a context with a timeout, but only if the timeout is longer than 0
9func ContextWithConditionalTimeout(parent context.Context, timeout int) (context.Context, context.CancelFunc) {
10 var (
11 ctx context.Context
12 cancel context.CancelFunc
13 )
14
15 if timeout <= 0 {
16 ctx, cancel = context.WithCancel(context.TODO())
17 } else {
18 ctx, cancel = context.WithTimeout(context.TODO(), time.Duration(timeout)*time.Second)
19 }
20
21 return ctx, cancel
22}

Callers 2

CmdInteractiveMethod · 0.92
RunMethod · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected