delay

Types

Type representing a delayed effect to be lazily evaluated

pub opaque type Delay(val, error)

Functions

pub fn all(effects: List(Delay(a, b))) -> Bool

Run all effects in sequence and return True if all succeed NOTE: this will always run every effect

pub fn any(effects: List(Delay(a, b))) -> Bool

Run all effects in sequence and return True if any succeeds NOTE: this is different than fallthrough/1 because it will always run every effect

pub fn delay_effect(func: fn() -> Result(a, b)) -> Delay(a, b)

Stores an effect to be run later, short circuiting on errors

pub fn drain(delayed: Delay(a, b)) -> Nil

Run a delayed effect and throw away the result short-circuiting if any in the chain returns an Error

pub fn every(effects: List(Delay(a, b))) -> List(Result(a, b))

Run every effect in sequence and get their results

pub fn fallthrough(effects: List(Delay(a, b))) -> Result(a, b)

Attempt multiple Delays until one returns an Ok unlike any/1 this will short circuit on the first Ok

pub fn flat_map(
  delayed: Delay(a, b),
  func: fn(a) -> Result(Delay(c, b), b),
) -> Delay(c, b)

Map and then flatten delayed

pub fn flatten(delayed: Delay(Delay(a, b), b)) -> Delay(a, b)

flatten a nested Delay

pub fn join(
  left: Delay(a, b),
  right: Delay(c, d),
) -> Delay(#(a, c), #(Option(b), Option(d)))

returns a delay, that joins two delays. If left fails right will not be run, if either fails the result will be an Error

pub fn map(
  delayed: Delay(a, b),
  func: fn(a) -> Result(c, b),
) -> Delay(c, b)

Chains an operation onto an existing delay. The result of the current delay will be lazily passed to func func will not be called if the delay has already returned an error

pub fn repeat(
  delayed: Delay(a, b),
  repetition: Int,
) -> List(Result(a, b))

Repeat a Delay and return the results in a list

pub fn retry(
  delayed: Delay(a, b),
  retries: Int,
  delay: Int,
) -> Delay(a, b)

Returns a new Delay that will be re-attempted retries times with delay ms in-between NOTE: delay is ignored in JS

pub fn retry_with_backoff(
  delayed: Delay(a, b),
  retries: Int,
) -> Delay(a, b)

Returns a Delay that will be re-attempted retries times with an increasing backoff delay NOTE: there is no backoff in JS

pub fn run(delayed: Delay(a, b)) -> Result(a, b)

Run a delayed effect and get the result short-circuiting if any in delay in the chain returns an Error

Search Document