Foundation.Poller (foundation v0.2.1)

Copy Markdown View Source

Generic polling loop with backoff and timeout controls.

Summary

Functions

Run a polling loop in a Task.

Await a polling task, converting exits into error tuples.

Run a polling loop until completion, error, timeout, or max attempts.

Types

backoff()

@type backoff() ::
  :none
  | Foundation.Backoff.Policy.t()
  | {:exponential, pos_integer(), pos_integer()}
  | (non_neg_integer() -> non_neg_integer())

step_result()

@type step_result() ::
  {:ok, term()}
  | {:retry, term()}
  | {:retry, term(), non_neg_integer()}
  | {:error, term()}
  | :retry

Functions

async(step_fun, opts \\ [])

@spec async(
  (non_neg_integer() -> step_result()),
  keyword()
) :: Task.t()

Run a polling loop in a Task.

await(task, timeout \\ :infinity)

@spec await(Task.t(), timeout()) :: {:ok, term()} | {:error, term()}

Await a polling task, converting exits into error tuples.

run(step_fun, opts \\ [])

@spec run(
  (non_neg_integer() -> step_result()),
  keyword()
) :: {:ok, term()} | {:error, term()}

Run a polling loop until completion, error, timeout, or max attempts.

The step_fun receives the current attempt (0-based).