VoIP.info Guide

Asterisk WaitForCondition: deferred expressions, polling and status evidence

Wait for a mutable condition without freezing its first value, while keeping expression ownership, poll interval, timeout, status and downstream call flow independently observable.

Reviewed 2026-10-15Current Asterisk branch-23-generated WaitForCondition, VARIABLE_EXISTS and GLOBAL_EXISTS references, branch 22 WaitForCondition reference, and current dialplan expression and conditional-application documentation reviewed October 15, 2026; installed branch, module packaging, exact dialplan, expression, channel, mutable-state owner, writer, timing, function cost and downstream call flow remain deployment specific; no host, module, dialplan, channel, variable, global, function, poll, packet or live call was inspected or testedAdvancedDocumentation based · not lab tested

Name the mutable state and its exact owner

WaitForCondition() repeatedly evaluates an expression, but a changing-looking name is not enough to prove that the application can see the value that another dialplan step updates. Record whether the value belongs to the current channel, an inherited child, a global variable, AstDB, shared state or a dialplan function, together with the writer and correlation key.

A caller channel, callee channel, Local-channel halves and transfer-created legs remain different variable owners. A linked ID can correlate them without merging their channel-local variables. Use an explicitly documented shared owner when a writer and waiter do not execute on the same channel.

Defer the expression instead of freezing its first value

The application syntax takes a replacement character followed by the expression. Asterisk documents that the replacement character substitutes for $ so the expression is passed into WaitForCondition() rather than evaluated before the application begins polling. The selected replacement character must not appear elsewhere in the expression.

Preserve the exact loaded dialplan string, after configuration generation but before runtime expansion. If the expression was evaluated only once at application entry, a later variable update cannot make the frozen result true. Treat escaping, quoting and replacement as part of the executable contract rather than presentation syntax.

Bound timeout and choose the poll interval deliberately

The documented syntax accepts timeout and interval in seconds. The current generated reference documents a 0.05-second default interval and no timeout by default. For a production call path, set an explicit timeout and a deliberate interval so caller treatment, resource occupancy and expected writer latency are bounded and reviewable.

A shorter interval increases evaluation frequency; it does not make the state owner correct or guarantee that an external update becomes visible. Record application start, each relevant writer timestamp, return time and selected values. Keep poll cadence distinct from overall timeout and from the business deadline.

Make truth and existence explicit

Asterisk conditional syntax treats an empty string and the string 0 as false, and other strings as true. Prefer an explicit quoted comparison when an empty, zero, text or numeric result has different meaning. VARIABLE_EXISTS() tests a channel variable while GLOBAL_EXISTS() tests a global variable; they are not interchangeable scope probes.

The current generated references publish those functions only from particular Asterisk patch levels, so confirm installed help before depending on them. Existence does not validate freshness, type, writer identity or business meaning. Capture those separately.

Avoid expensive or side-effecting work in a polled expression

Because the application evaluates the expression at each poll, a function embedded in that expression can be invoked repeatedly. As an operational design rule, keep the expression cheap and side-effect free, or move the external lookup into a controlled writer that updates an explicitly owned state value. This is deployment guidance derived from repeated evaluation, not a claim that every function has the same cost or behavior.

Do not turn a database write, remote request, destructive read or opaque custom function into an accidental high-frequency loop. If a lookup is necessary, define its timeout, error result, cache behavior and observability before choosing the interval.

Branch on status, then verify downstream call flow

The generated application reference documents WAITFORCONDITIONSTATUS values TRUE, FAILURE, TIMEOUT and HANGUP. Preserve the value immediately after the application on the channel that ran it. A TRUE status proves the evaluated condition became true under that contract; it does not prove a later playback, bridge, API call or caller outcome succeeded.

Test authorized true, timeout, expression-failure and hangup paths with bounded timing and rollback. Retain the exact expression, state owner, writer event, return status and next executed priority. No host, module, dialplan, channel, variable, global, function, poll, packet or live call was inspected or tested for this guide.

Sources & applicability

Primary references for the technical details above. Operational examples and planning checklists are VoIP.info editorial guidance.

Examples require adaptation to your topology. No live PBX or hardware testing is claimed.