Temporalex.Workflow.API (Temporalex v0.2.0)

Copy Markdown View Source

Functions available to workflow code. All calls delegate to the executor via Process.get(:__temporal_executor__).

Sequential primitives (available anywhere)

Structured concurrency hosts

Async-only (inside {:async, fn, state} handlers)

Summary

Functions

Check if the workflow has been cancelled.

Mark a patch as deprecated after all pre-patch executions complete.

Execute an activity. Blocks until the activity completes or fails.

Execute a local activity. Blocks until completion.

Execute functions concurrently. Blocks until all complete. Returns results in the same order as input functions.

Workflow versioning. Returns true on new executions, replays from history.

Publish a state snapshot visible to query handlers. Replaces previous state.

Enter a message-processing loop. Blocks the caller.

Execute fun once and return its value.

Durable timer. Blocks for duration_ms milliseconds.

Start a child workflow. Blocks until the child completes or fails.

Atomically read-modify-write the enclosing receive block's state. Only available inside async handler processes.

Block until a signal with name arrives. Consumes one from the buffer.

Functions

cancelled?()

Check if the workflow has been cancelled.

deprecate_patch(patch_id)

Mark a patch as deprecated after all pre-patch executions complete.

execute_activity(type, input, opts \\ [])

Execute an activity. Blocks until the activity completes or fails.

execute_local_activity(type, input, opts \\ [])

Execute a local activity. Blocks until completion.

Local activities are short, in-process operations that the worker runs directly without round-tripping through the Temporal task queue. Use them for cheap deterministic-with-side-effects work (id generation, current time, small lookups). Their result is recorded in workflow history, so they survive worker crashes — unlike side_effect/1 — making them the safe replacement for non-durable inline functions.

Options:

  • :start_to_close_timeout_ms (default 30_000)

parallel(fns)

Execute functions concurrently. Blocks until all complete. Returns results in the same order as input functions.

patched?(patch_id)

Workflow versioning. Returns true on new executions, replays from history.

publish_state(state)

Publish a state snapshot visible to query handlers. Replaces previous state.

receive(initial_state, opts)

Enter a message-processing loop. Blocks the caller.

Options

  • :signal — map of signal name to handler function
  • :update — map of update name to handler (or {handler, validator: fn})
  • :timeout — milliseconds before auto-exit with {:timeout, state}

Handler return values

Signal handlers: {:noreply, state}, {:stop, state}, {:async, fn, state} Update handlers: {:reply, response, state}, {:stop, response, state}, {:async, fn, state}

The state in {:async, fn, state} is ignored; use update_state/1 inside the async fn to mutate the receive state safely alongside other async work.

side_effect(fun)

Execute fun once and return its value.

Deprecated for non-deterministic work. Use execute_local_activity/3 (or defactivity ..., local: true) instead — local activities are recorded in workflow history and survive worker crashes/cache evictions.

side_effect/1 is not durable across cache evictions: if the workflow is evicted and later re-activated on a different worker, fun runs again with a new value. Safe only for values whose re-computation is acceptable (e.g. monitoring or logging instrumentation).

sleep(duration_ms)

Durable timer. Blocks for duration_ms milliseconds.

start_child_workflow(module, args, opts \\ [])

Start a child workflow. Blocks until the child completes or fails.

Options: :workflow_id, :task_queue, :cancellation_type, :parent_close_policy.

update_state(fun)

Atomically read-modify-write the enclosing receive block's state. Only available inside async handler processes.

The function receives current state and returns {return_value, new_state}.

wait_for_signal(name)

Block until a signal with name arrives. Consumes one from the buffer.