Wait
APPLIES TO: All API Management tiers
The wait
policy executes its immediate child policies in parallel, and waits for either all or one of its immediate child policies to complete before it completes. The wait
policy can have as its immediate child policies one or more of the following: send-request
, cache-lookup-value
, and choose
policies.
Note
Set a policy's elements and child elements in the order provided in the policy statement. Learn more about how to set or edit API Management policies.
Policy statement
<wait for="all | any">
<!--Wait policy can contain send-request, cache-lookup-value,
and choose policies as child elements -->
</wait>
Attributes
Attribute | Description | Required | Default |
---|---|---|---|
for | Determines whether the wait policy waits for all immediate child policies to be completed or just one. Allowed values are:- all - wait for all immediate child policies to complete- any - wait for any immediate child policy to complete. Once the first immediate child policy has completed, the wait policy completes and execution of any other immediate child policies is terminated.Policy expressions are allowed. |
No | all |
Elements
May contain as child elements only send-request
, cache-lookup-value
, and choose
policies.
Usage
- Policy sections: inbound, outbound, backend
- Policy scopes: global, workspace, product, API, operation
- Gateways: classic, consumption, self-hosted
Example
In the following example, there are two choose
policies as immediate child policies of the wait
policy. Each of these choose
policies executes in parallel. Each choose
policy attempts to retrieve a cached value. If there is a cache miss, a backend service is called to provide the value. In this example the wait
policy does not complete until all of its immediate child policies complete, because the for
attribute is set to all
. In this example the context variables (execute-branch-one
, value-one
, execute-branch-two
, and value-two
) are declared outside of the scope of this example policy.
<wait for="all">
<choose>
<when condition="@((bool)context.Variables["execute-branch-one="])">
<cache-lookup-value key="key-one" variable-name="value-one" />
<choose>
<when condition="@(!context.Variables.ContainsKey("value-one="))">
<send-request mode="new" response-variable-name="value-one">
<set-url>https://backend-one</set-url>
<set-method>GET</set-method>
</send-request>
</when>
</choose>
</when>
</choose>
<choose>
<when condition="@((bool)context.Variables["execute-branch-two="])">
<cache-lookup-value key="key-two" variable-name="value-two" />
<choose>
<when condition="@(!context.Variables.ContainsKey("value-two="))">
<send-request mode="new" response-variable-name="value-two">
<set-url>https://backend-two</set-url>
<set-method>GET</set-method>
</send-request>
</when>
</choose>
</when>
</choose>
</wait>
Related policies
Next steps
For more information about working with policies, see:
- Tutorial: Transform and protect your API
- Policy reference for a full list of policy statements and their settings
- Policy expressions
- Set or edit policies
- Policy samples