How to Use context.WithoutCancel (Go 1.21+)

context.WithoutCancel creates a derived context that ignores parent cancellation while preserving values and deadlines.

Use context.WithoutCancel to create a derived context that ignores cancellation signals from its parent while preserving values and deadlines.

import "context"

// ctx is a cancellable context
ctx, cancel := context.WithCancel(context.Background())

// newCtx ignores cancellation from ctx but keeps its values and deadline
newCtx := context.WithoutCancel(ctx)

// cancel() will NOT cancel newCtx
cancel()

// newCtx.Err() returns nil (unless deadline passed)
if newCtx.Err() != nil {
    // handle error
}