ktesting: add WithoutCancel

This closes a gap compared to the context package. It's useful when combined
with Ginkgo to keep something running beyond the end of the Ginkgo BeforeEach
or It node.
This commit is contained in:
Patrick Ohly
2025-07-01 15:48:44 +02:00
parent e01603b2e3
commit e5f57d2cfa

View File

@@ -43,6 +43,13 @@ func WithCancel(tCtx TContext) TContext {
}
}
// WithoutCancel causes the returned context to ignore cancellation of its parent.
func WithoutCancel(tCtx TContext) TContext {
tCtx.Helper()
ctx := context.WithoutCancel(tCtx)
return WithContext(tCtx, ctx)
}
// WithTimeout sets up new context with a timeout. Canceling the timeout gets
// registered in a [TContext.Cleanup] callback. [TContext.Cancel] cancels only
// the new context. The cause is used as reason why the context is canceled