Logo Orsak

Effect Module

Resilience functions for effects: retrying with backoff, logging errors, and running effects perpetually.

Functions and values

Function or value Description

addDelay baseDelay effect

Full Usage: addDelay baseDelay effect

Parameters:
Returns: Effect<'a, bool, 'b>
Type parameters: 'a, 'b

Takes a base delay and an effect, and returns an effect with a delay added at the end, if the provided effect returned false. If the effect is re-run, the delay is increased each time the original effect returns false. If the effect returns true, no delay is added, and the calculated delay is reset to 0.

baseDelay : float<MeasureProduct<s, MeasureOne>>

effect : Effect<'a, bool, 'b>

Returns: Effect<'a, bool, 'b>

addDelayOnError baseDelay effect

Full Usage: addDelayOnError baseDelay effect

Parameters:
Returns: Effect<'a, 'a0, 'e>
Type parameters: 'a, 'a, 'e

Takes a base delay and an effect, and returns an effect with a delay added at the end, if the provided effect returned with an error. If the effect is re-run, the delay is increased each time the original effect returns an error. If the effect returns Ok, no delay is added, and the calculated delay is reset to 0.

baseDelay : float<MeasureProduct<s, MeasureOne>>

effect : Effect<'a, 'a0, 'e>

Returns: Effect<'a, 'a0, 'e>

addDelayOnErrorWithMax baseDelay maxDelay effect

Full Usage: addDelayOnErrorWithMax baseDelay maxDelay effect

Parameters:
Returns: Effect<'a, 'a0, 'e>
Type parameters: 'a, 'a, 'e

Takes a base delay and an effect, and returns an effect with a delay added at the end, if the provided effect returned with an error. If the effect is re-run, the delay is increased each time the original effect returns an error. If the effect returns Ok, no delay is added, and the calculated delay is reset to 0.

baseDelay : float<MeasureProduct<s, MeasureOne>>

maxDelay : float<MeasureProduct<s, MeasureOne>>

effect : Effect<'a, 'a0, 'e>

Returns: Effect<'a, 'a0, 'e>

addDelayWithMax baseDelay maxDelay effect

Full Usage: addDelayWithMax baseDelay maxDelay effect

Parameters:
Returns: Effect<'a, bool, 'b>
Type parameters: 'a, 'b

Takes a base delay and en effect, and returns an effect with a delay added at the end, if the provided effect returned false. If the effect is re-run, the delay is increased each time the original effect returns false. If the effect returns true, no delay is added, and the calculated delay is reset to 0. The delay till will not be longer than maxDelay

baseDelay : float<MeasureProduct<s, MeasureOne>>

maxDelay : float<MeasureProduct<s, MeasureOne>>

effect : Effect<'a, bool, 'b>

Returns: Effect<'a, bool, 'b>

addDelayWithMax_ baseDelay maxDelay effect

Full Usage: addDelayWithMax_ baseDelay maxDelay effect

Parameters:
Returns: Effect<'a, unit, 'b>
Type parameters: 'a, 'b

Takes a base delay and an effect, and returns an effect with a delay added at the end, if the provided effect returned false. If the effect is re-run, the delay is increased each time the original effect returns false. If the effect returns true, no delay is added, and the calculated delay is reset to 0. The delay till will not be longer than maxDelay Then the bool is discarded and unit is returned.

baseDelay : float<MeasureProduct<s, MeasureOne>>

maxDelay : float<MeasureProduct<s, MeasureOne>>

effect : Effect<'a, bool, 'b>

Returns: Effect<'a, unit, 'b>

addDelay_ baseDelay effect

Full Usage: addDelay_ baseDelay effect

Parameters:
Returns: Effect<'a, unit, 'b>
Type parameters: 'a, 'b

Takes a base delay and an effect, and returns an effect with a delay added at the end, if the provided effect returned false. If the effect is re-run, the delay is increased each time the original effect returns false. If the effect returns true, no delay is added, and the calculated delay is reset to 0. Then the bool is discarded and unit is returned.

baseDelay : float<MeasureProduct<s, MeasureOne>>

effect : Effect<'a, bool, 'b>

Returns: Effect<'a, unit, 'b>

logError log effect

Full Usage: logError log effect

Parameters:
    log : ILoggerFactory -> 'e -> unit - Logs an error, given the environment's logger factory
    effect : Effect<'a, 'a0, 'e> - The effect

Returns: Effect<'a, 'a0, 'e>
Type parameters: 'e, 'a, 'a (requires :> Microsoft.Extensions.Logging.ILoggerFactory)

Logs the error when the effect fails, with log, and then fails with the same error. The environment has to be an ILoggerFactory.

log : ILoggerFactory -> 'e -> unit

Logs an error, given the environment's logger factory

effect : Effect<'a, 'a0, 'e>

The effect

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

 importPrices ()
 |> Effect.logError (fun factory err ->
     factory.CreateLogger("Prices").LogError("Import failed: {Error}", err))

repeatUntilCancellation token effect

Full Usage: repeatUntilCancellation token effect

Parameters:
Returns: Effect<'a, Never, 'b>
Type parameters: 'a, 'b

Re-runs the provided effect until the provided token signals cancellation. If the provided effect fails, it returns with an error.

token : CancellationToken

effect : Effect<'a, unit, 'b>

Returns: Effect<'a, Never, 'b>

retryForever effect

Full Usage: retryForever effect

Parameters:
    effect : Effect<'a, 'a0, 'b> -

Returns: Effect<'a, 'a0, Never>
Type parameters: 'a, 'a, 'b

Perpetually returns the provided effect, in case of error

effect : Effect<'a, 'a0, 'b>

Returns: Effect<'a, 'a0, Never>

retryTimes times effect

Full Usage: retryTimes times effect

Parameters:
    times : int64 -
    effect : Effect<'a, 'a0, 'b> -

Returns: Effect<'a, 'a0, 'b>
Type parameters: 'a, 'a, 'b

If the provided effect returns an error, tries to re-run it up to times times.

times : int64

effect : Effect<'a, 'a0, 'b>

Returns: Effect<'a, 'a0, 'b>

Type something to start searching.