Logo Orsak

Cancellation Module

Effects that run other effects in a CancellationScope. The environment begins the scope and grows into the environment of the effect, which provides the scope as its ICancellationProvider: so CancellationSource.getToken, Time.delay and the retry delays of Orsak.Resilience see the scope's token, and CancellationSource.cancel cancels only the scope.

Functions and values

Function or value Description

timeout duration onTimeout body

Full Usage: timeout duration onTimeout body

Parameters:
    duration : TimeSpan - How long the effect may run.
    onTimeout : 'e - The error to fail with when it times out.
    body : Effect<'Inner, 'a, 'e> - The effect to run in the scope, an effect of the grown environment.

Returns: Effect<'Outer, 'a, 'e>
Type parameters: 'Outer, 'Inner, 'a, 'e (requires :> Orsak.Scoped.IGrowsInto<Orsak.CancellationScope,'Inner>)

Runs body in a new cancellation scope that is cancelled after duration, and fails with onTimeout if it is. Unlike Effect.timeout, the effect is stopped: the effects in it that take the scope's token end when it is cancelled. The time is measured on the clock of an environment that is an ITimeProvider, so a fake clock decides when it times out, and on the system clock otherwise.

Cancelling the token the scope is linked to, or cancelling the scope from within, is not a timeout: the cancellation propagates as an exception, as without the timeout.

duration : TimeSpan

How long the effect may run.

onTimeout : 'e

The error to fail with when it times out.

body : Effect<'Inner, 'a, 'e>

The effect to run in the scope, an effect of the grown environment.

Returns: Effect<'Outer, 'a, 'e>
Example

 lookupAddress postcode
 |> Cancellation.timeout (TimeSpan.FromSeconds 2.0) AddressLookupTimedOut

within body

Full Usage: within body

Parameters:
    body : Effect<'Inner, 'a, 'e> - The effect to run in the scope, an effect of the grown environment.

Returns: Effect<'Outer, 'a, 'e>
Type parameters: 'Outer, 'Inner, 'a, 'e (requires :> Orsak.Scoped.IGrowsInto<Orsak.CancellationScope,'Inner>)

Runs body in a new cancellation scope, disposed when body ends. In an environment that is in a scope already, the new scope is nested in it, when the environment begins it so, with CancellationScope.NestedIn.

body : Effect<'Inner, 'a, 'e>

The effect to run in the scope, an effect of the grown environment.

Returns: Effect<'Outer, 'a, 'e>
Example

 let importAll files =
     eff {
         for file in files do
             do! import file
     }
     |> Cancellation.within
val importAll: files: 'a -> 'b
val files: 'a

Type something to start searching.