wait pauses the run without holding any process open, so a run can wait minutes or days and
still pick up where it left off. Use until when you know the wake time in advance, a polling
wait when you have to keep asking an outside system, and a task wait when you created a task with
mode: create and did something else before waiting for the answer.
A wait has five forms. Each body must match exactly one of them.
Syntax
Duration
wait id=let-billing-settle
Instant
wait id=wait-for-effective-date
Polling
wait id=wait-for-payment
RSL log
wait id=wait-for-decision
Task
wait id=wait-for-refund-approval
Fields
Durations
duration, every, timeout and next_poll.at_most take a duration: a positive whole number
followed by one unit, ms, s, m, h or d. For example 90s, 15m or 5d. Fractions,
signs, spaces and combined units such as 1h30m are invalid.
Duration form
Instant form
until is either one reference or one quoted RFC 3339 date-time, such as
'2026-12-31T05:00:00Z'. A reference must point to a value declared as
{ type: string, format: date-time }; a plain string is refused. Templates, ?? and built
values are invalid. An instant that has already passed continues at once.
The instant form binds no output. Later steps keep reading the original value.
Polling form
Use exactly one of
until.equals and until.in.
The function must have an effect. A pure ts function can’t be polled: called with the same
input, it can’t see anything change. See Functions and effects.
The matched schema narrows the result. until.schema describes a result that has matched. It
must have the same shape as the function’s result schema. It may only:
- add existing property names to
required; - replace an
enumwith a nonempty subset of its values; or - replace an
enumwith aconstthat was one of its values.
until.path and admit the equals value, or every value in in. This lets a
function return { status: pending } while it waits and a typed { status: settled, ... } when it
is done.
When the member at until.path is a plain string in the result schema, with no enum, the
matched schema keeps it a plain string. The wait still ends on the values you list, but a later
choice can’t route on that member directly. Derive a
closed value first with a pure ts function called through call.
Results of Effective API operations are the common case: their string values stay open so new
values don’t break running procedures.
A hint sets the next interval. With next_poll, after a result that doesn’t match, the next
interval is the hinted number times unit, raised to at least every and lowered to at most
at_most. A missing or null hint uses every. A hint can never extend the wait past timeout.
Without next_poll, polls are every apart. There is no other backoff syntax: a function that
wants backoff returns growing hints.
on_timeout ends the wait when time runs out.
fail: <code>fails the run. The code is lowercase words joined by hyphens, such asrefund-payment-not-final. The run’sfailure.codeispoll_timeout, and its message is your code. Nothing is bound.value: <object>binds this value tooutputand continues. The value may hold literals and plain references, but no templates, optional references or??. It must matchuntil.schema.
RSL log form
Use this form to wait until an RSL submission log on one of your programs reaches a decision.
An RSL log wait reads the log’s status, the same result as
Get the status of a log. It has no
poll, every or next_poll.
- It reads the status when it starts. Every write to the log wakes it to read again at once. It also reads every 15 minutes in case a wake is lost.
- It routes on
decision:refused,incomplete,referred,clear,boundorclosed.decisionis deprecated in favor ofstatus.status; see the status operation for its dates. - A log whose decision is
boundorclosedtakes no more writes, so it can never match later. If a read returns one of them and it doesn’t matchuntil, the wait applieson_timeoutat once. Listboundorclosedinuntilto end on them as a match instead. - A read the API refuses, such as an unknown log or a program the run can’t read, fails the run.
Task form
task is the exact handle, such as $approval_task. A member such as $approval_task.url is
invalid. The wait doesn’t create the task again or change who it is assigned to. output has the
same shape as a blocking task’s output, so read the answer under .value, such as
$approval.value.approved.
Example
Wait ten minutes before the next step:wait id=let-billing-settle
Cancel on the effective date
This procedure holds a Northwind Mutual cancellation until the effective date and time the caller passes in. The instant input needs adate-time schema.
cancellation-on-effective-date.procedure.md
Wait for a refund payment
This procedure asks an illustrative billing system,billing.northwind.example, about a refund
payment until it is settled or returned. The billing system can say how long to wait before
asking again; the wait never asks more often than every 15 minutes or less often than every 6
hours, and gives up after 5 days.
wait-for-refund-payment.procedure.md
payment-final narrows status to the two values that end the wait, so a later choice on
$payment.status only has to cover settled and returned.
Create a task, then wait for it
Atask with mode: create returns a handle as soon as the task exists. Steps between the task
and the wait can use the handle, for example to post $approval_task.url to your team’s chat.
task id=create-refund-approval
wait id=wait-for-refund-approval
$approval.value.approved then holds the answer.
On retry and resume
- A waiting run holds nothing open. It resumes after restarts and deployments and wakes at the same time it would have.
- An instant is fixed once.
untilis read once, when the wait starts, and the instant is recorded. A value that isn’t an RFC 3339 date-time fails the run withschema_mismatch. - A polling wait has one deadline. It is set when polling starts. Time spent inside the function counts against it, as does the time between polls.
- Polls never overlap. The next poll starts only after the previous one has finished.
- Each poll is its own call. Each call has its own stable identity. If a poll’s outcome can’t be determined, the run fails for you to check, rather than polling again.
- Effective API reads keep trying. When an Effective API read gets no usable answer (HTTP 408, 429 or 5xx, or no response), the wait repeats the same read until the API answers or the deadline passes. An outage of hours doesn’t end a wait of days. A read the API refuses (any other 4xx) fails the run.
- The deadline wins once. When the deadline passes during a poll, that poll is cancelled and
on_timeoutis applied once. A result that arrives later is recorded but can’t reopen the wait or bindoutput. - Only the match binds. Results that don’t match are recorded in the run’s history but never
bound. The matching result, or the
on_timeoutvalue, binds tooutputin one step. - Hints replay the same way. The interval after a hint is worked out from the recorded result,
so a resumed run keeps the same schedule. A hint that is negative or not a whole number fails the
run with
schema_mismatch. - A poll may run early. Effective can wake a polling wait early when the source it reads has changed, as it does for every write to an RSL log. A wake only causes another read; the wait still ends only on a match. Write poll functions so that an extra read is harmless.
- A task answer is never lost. If the person answers before the task wait starts, the answer is kept and delivered when the wait starts.
Common errors
next_poll.at_most shorter than every, and on_timeout with both fail and value, are
also refused.
See also
task: create a task withmode: create.call: call a function or effect once.- Functions and effects: write the effect a polling wait calls.
choice: branch on the value that ended a wait.- Triggers: start runs on a schedule. A
waitis a single timer, not a schedule.