RuntimeModule
PackageAxial
Runtime helpers for execution-time concerns like cancellation, scope, timeout, retry, and cleanup.
Summary
| Name | Signature | Synopsis |
|---|---|---|
| cancellationToken | Runtime.cancellationToken | Reads the current runtime cancellation token. |
| catchCancellation | Runtime.catchCancellation handler flow | Catches raised by a flow and converts it into a typed error. |
| ensureNotCanceled | Runtime.ensureNotCanceled canceledError | Returns a typed error immediately when the runtime token is already canceled. |
| sleep | Runtime.sleep delay | Suspends the flow for the specified duration, observing cancellation. |
| scope | Runtime.scope | Reads the current runtime scope. |
| annotations | Runtime.annotations | Reads the current runtime annotations. |
| traceId | Runtime.traceId | Reads the current runtime trace id annotation if one is present. |
| fiberId | Runtime.fiberId | Reads the current fiber id from the ambient runtime context. |
| timeout | Runtime.timeout after timeoutError flow | Fails with the supplied typed error when the flow does not complete before the timeout. |
| timeoutToOk | Runtime.timeoutToOk after value flow | Returns the supplied success value when the flow does not complete before the timeout. |
| timeoutToError | Runtime.timeoutToError after error flow | Alias for timeout that emphasizes typed failure on timeout. |
| timeoutWith | Runtime.timeoutWith after fallback flow | Runs a fallback flow when the source flow does not complete before the timeout. |
| retry | Runtime.retry policy flow | Retries typed failures according to the specified policy. |
| supervise | Runtime.supervise policy flow | Restarts a flow that terminates with an unexpected defect, according to the specified policy. |
Reads the current runtime cancellation token.
Returns
Flow<'env, 'error, CancellationToken>
Catches OperationCanceledException raised by a flow and converts it into a typed error.
Parameters
| Name | Type | Description |
|---|---|---|
| handler | OperationCanceledException -> 'error | Maps the cancellation exception into the workflow error type. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
Returns a typed error immediately when the runtime token is already canceled.
Parameters
| Name | Type | Description |
|---|---|---|
| canceledError | 'error | The error to return when cancellation has been requested. |
Returns
Flow<'env, 'error, unit>
Suspends the flow for the specified duration, observing cancellation.
Parameters
| Name | Type | Description |
|---|---|---|
| delay | TimeSpan | The duration to sleep. |
Returns
Flow<'env, 'error, unit>
Reads the current runtime annotations.
Returns
Flow<'env, 'error, Map<string, string>>
Reads the current runtime trace id annotation if one is present.
Returns
Flow<'env, 'error, string option>
Reads the current fiber id from the ambient runtime context.
Returns
Flow<'env, 'error, FiberId>
Fails with the supplied typed error when the flow does not complete before the timeout.
Parameters
| Name | Type | Description |
|---|---|---|
| after | TimeSpan | The timeout duration. |
| timeoutError | 'error | The typed error returned when the timeout wins. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
Returns the supplied success value when the flow does not complete before the timeout.
Parameters
| Name | Type | Description |
|---|---|---|
| after | TimeSpan | The timeout duration. |
| value | 'value | The success value returned when the timeout wins. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
Alias for
timeout that emphasizes typed failure on timeout.Parameters
| Name | Type | Description |
|---|---|---|
| after | TimeSpan | |
| error | 'error | |
| flow | Flow<'env, 'error, 'value> |
Returns
Flow<'env, 'error, 'value>
Runs a fallback flow when the source flow does not complete before the timeout.
Parameters
| Name | Type | Description |
|---|---|---|
| after | TimeSpan | The timeout duration. |
| fallback | unit -> Flow<'env, 'error, 'value> | Creates the fallback flow when the timeout wins. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
Retries typed failures according to the specified policy.
Parameters
| Name | Type | Description |
|---|---|---|
| policy | RetryPolicy<'error> | The retry policy. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>

