withFlippingContext
inline suspend fun <T> withFlippingContext(context: FlippingExecutionContext, crossinline block: suspend () -> T): T(source)
Execute a block with the given FlippingExecutionContext.
The context is available to all suspend calls within the block via currentFlippingContext. When the block completes (normally or exceptionally), the previous context is automatically restored.
Contexts can be nested - inner contexts completely replace outer ones:
withFlippingContext(FlippingExecutionContext(ContextKeys.ENVIRONMENT to "prod")) {
// environment = "prod"
withFlippingContext(FlippingExecutionContext(ContextKeys.ENVIRONMENT to "staging")) {
// environment = "staging" (replaced, not merged)
}
// environment = "prod" (restored)
}Content copied to clipboard
For merging behavior, use withFlippingParameters instead.
Return
The result of the block
Parameters
context
The context to use within the block
block
The suspending block to execute