RuntimeModule

PackageAxial
Runtime helpers for execution-time concerns like cancellation, scope, timeout, retry, and cleanup.

Summary

NameSignatureSynopsis
Operations
cancellationTokenRuntime.cancellationToken Reads the current runtime cancellation token.
catchCancellationRuntime.catchCancellation handler flowCatches raised by a flow and converts it into a typed error.
ensureNotCanceledRuntime.ensureNotCanceled canceledErrorReturns a typed error immediately when the runtime token is already canceled.
sleepRuntime.sleep delaySuspends the flow for the specified duration, observing cancellation.
scopeRuntime.scope Reads the current runtime scope.
annotationsRuntime.annotations Reads the current runtime annotations.
traceIdRuntime.traceId Reads the current runtime trace id annotation if one is present.
fiberIdRuntime.fiberId Reads the current fiber id from the ambient runtime context.
timeoutRuntime.timeout after timeoutError flowFails with the supplied typed error when the flow does not complete before the timeout.
timeoutToOkRuntime.timeoutToOk after value flowReturns the supplied success value when the flow does not complete before the timeout.
timeoutToErrorRuntime.timeoutToError after error flowAlias for timeout that emphasizes typed failure on timeout.
timeoutWithRuntime.timeoutWith after fallback flowRuns a fallback flow when the source flow does not complete before the timeout.
retryRuntime.retry policy flowRetries typed failures according to the specified policy.
superviseRuntime.supervise policy flowRestarts a flow that terminates with an unexpected defect, according to the specified policy.

Operations

kind:member

cancellationToken

Runtime.cancellationToken
Member
Reads the current runtime cancellation token.

Returns

Flow<'env, 'error, CancellationToken>
kind:member

catchCancellation

Runtime.catchCancellation handler flow
Member
Catches OperationCanceledException raised by a flow and converts it into a typed error.

Parameters

NameTypeDescription
handlerOperationCanceledException -> 'errorMaps the cancellation exception into the workflow error type.
flowFlow<'env, 'error, 'value>The source flow.

Returns

Flow<'env, 'error, 'value>
kind:member

ensureNotCanceled

Runtime.ensureNotCanceled canceledError
Member
Returns a typed error immediately when the runtime token is already canceled.

Parameters

NameTypeDescription
canceledError'errorThe error to return when cancellation has been requested.

Returns

Flow<'env, 'error, unit>
kind:member

sleep

Runtime.sleep delay
Member
Suspends the flow for the specified duration, observing cancellation.

Parameters

NameTypeDescription
delayTimeSpanThe duration to sleep.

Returns

Flow<'env, 'error, unit>
kind:member

scope

Runtime.scope
Member
Reads the current runtime scope.

Returns

Flow<'env, 'error, Scope>
kind:member

annotations

Runtime.annotations
Member
Reads the current runtime annotations.

Returns

Flow<'env, 'error, Map<string, string>>
kind:member

traceId

Runtime.traceId
Member
Reads the current runtime trace id annotation if one is present.

Returns

Flow<'env, 'error, string option>
kind:member

fiberId

Runtime.fiberId
Member
Reads the current fiber id from the ambient runtime context.

Returns

Flow<'env, 'error, FiberId>
kind:member

timeout

Runtime.timeout after timeoutError flow
Member
Fails with the supplied typed error when the flow does not complete before the timeout.

Parameters

NameTypeDescription
afterTimeSpanThe timeout duration.
timeoutError'errorThe typed error returned when the timeout wins.
flowFlow<'env, 'error, 'value>The source flow.

Returns

Flow<'env, 'error, 'value>
kind:member

timeoutToOk

Runtime.timeoutToOk after value flow
Member
Returns the supplied success value when the flow does not complete before the timeout.

Parameters

NameTypeDescription
afterTimeSpanThe timeout duration.
value'valueThe success value returned when the timeout wins.
flowFlow<'env, 'error, 'value>The source flow.

Returns

Flow<'env, 'error, 'value>
kind:member

timeoutToError

Runtime.timeoutToError after error flow
Member
Alias for timeout that emphasizes typed failure on timeout.

Parameters

NameTypeDescription
afterTimeSpan
error'error
flowFlow<'env, 'error, 'value>

Returns

Flow<'env, 'error, 'value>
kind:member

timeoutWith

Runtime.timeoutWith after fallback flow
Member
Runs a fallback flow when the source flow does not complete before the timeout.

Parameters

NameTypeDescription
afterTimeSpanThe timeout duration.
fallbackunit -> Flow<'env, 'error, 'value>Creates the fallback flow when the timeout wins.
flowFlow<'env, 'error, 'value>The source flow.

Returns

Flow<'env, 'error, 'value>
kind:member

retry

Runtime.retry policy flow
Member
Retries typed failures according to the specified policy.

Parameters

NameTypeDescription
policyRetryPolicy<'error>The retry policy.
flowFlow<'env, 'error, 'value>The source flow.

Returns

Flow<'env, 'error, 'value>
kind:member

supervise

Runtime.supervise policy flow
Member
Restarts a flow that terminates with an unexpected defect, according to the specified policy.

Parameters

NameTypeDescription
policySupervisePolicyThe supervision policy.
flowFlow<'env, 'error, 'value>The source flow.

Returns

Flow<'env, 'error, 'value>