Slither.Stage behaviour (Slither v0.1.0)

Copy Markdown View Source

Behaviour for a single processing step in a Slither pipeline.

Every stage can implement handle_item/3 (scalar path) and/or handle_batch/3 (vectorized path). The pipe runner chooses the most efficient path based on stage capabilities and batch boundaries.

Result Types

  • {:ok, [items]} — emit items downstream (1:1 or 1:many)
  • {:route, destination, [items]} — route items to a named output
  • {:routed, %{dest => [items]}} — batch routing to multiple outputs
  • {:skip, reason} — drop the item
  • {:error, reason} — error

Summary

Callbacks

Process a batch of items. Optional — defaults to mapping handle_item/3.

Process a single item. Return transformed items for downstream.

Initialize the stage with options. Returns state passed to handlers.

Clean up stage resources.

Types

batch_result()

@type batch_result() ::
  {:ok, [Slither.Item.t()]}
  | {:routed, %{required(atom()) => [Slither.Item.t()]}}
  | {:error, term()}

item_result()

@type item_result() ::
  {:ok, [Slither.Item.t()]}
  | {:route, atom(), [Slither.Item.t()]}
  | {:skip, term()}
  | {:error, term()}

Callbacks

handle_batch(list, t, state)

(optional)
@callback handle_batch([Slither.Item.t()], Slither.Context.t(), state :: term()) ::
  batch_result()

Process a batch of items. Optional — defaults to mapping handle_item/3.

handle_item(t, t, state)

@callback handle_item(Slither.Item.t(), Slither.Context.t(), state :: term()) ::
  item_result()

Process a single item. Return transformed items for downstream.

init(keyword)

(optional)
@callback init(keyword()) :: {:ok, term()} | {:error, term()}

Initialize the stage with options. Returns state passed to handlers.

shutdown(state)

(optional)
@callback shutdown(state :: term()) :: :ok

Clean up stage resources.