Loop block V2Beta
Learn how to run queries for each item in a data set during a workflow.
:::beta Beta availability
Loop block v2 is available on Retool Cloud and Self-hosted Retool 3.42 or later. Request access →
:::
A Loop block contains an embedded block which runs for each evaluated item in an array. You use value
and index
to reference evaluated items and their indexes.
For example, you can automate a welcome email to new customers and customize the message for each recipient, using values like {{ value.email }}
and {{ value.name }}
.
Configure execution mode
Loop blocks support different modes for processing loop iterations:
- Parallel: Executes all iterations simultaneously.
- Sequential: Executes each iteration one at a time.
- Batch: Combines parallel and sequential modes to execute a parallel iterations in batches.
Within a Loop block, set the Execution mode to the mode you want to use.
Both modes include an optional delay between iterations. This can help prevent rate limits if you're making API requests for a large number of iterations.
Parallel
Parallel mode processes all iterations concurrently. For example, a Loop block that iterates through a list of users to update their information makes the same API request simultaneously.
Parallel loops complete more quickly than sequential or batched loops, resulting in shorter run times. Parallel loops are best for processing small amounts of data. Looping through large datasets can result in API limits or degraded service of your data source.
Sequential
Sequential mode processes each iteration sequentially. Each iteration must complete before the next one starts. For example, a Loop block that iterates through a list of users to update their information makes the same API request one at a time.
If you want to add a delay between sequential iterations, set Iteration delay (ms) to the desired amount of time.
Sequential loops take longer to process as each iteration must complete before the next one begins. This is especially useful if you're using APIs with strict rate limits or need to make the minimum amount of changes per iteration.
Batch
Runs a number of iterations in parallel, waiting for all to complete before moving to the next batch. Update Batch size to specify how many iterations should run per batch (default is 10
).
If you want to add a delay between batched iterations, set Batch delay (ms) to the desired amount of time.
For example, a Loop block that iterates through a list of users to update their information makes the same API request simultaneously.
Batched loops are a combination of parallel and sequential loops. You can find the right balance between concurrent iterations and the delay between each batch to find the right balance of speed and effectiveness.
Configure block settings
You can configure the following settings for Loop blocks.
Timeout after (ms)
The duration to wait before each iteration of the block times out. Default is 10000
. Maximum is 30000
.
Note that this timeout is only taken into account when running the entire workflow, not when previewing a single block run.
Retry count
The maximum number of attempts to retry an iteration of the loop if an error is returned.
Interval
The minimum length of time to wait between query retries. This is useful if a query is triggering a rate limit.
Exponential
Whether to increase the interval between retries, also known as exponential backoff. This is useful for handling rate limits.
Coefficient
When exponential backoff is enabled, the constant factor by which the time delay between retry attempts increases after each failure.
Max interval
When exponential backoff is enabled, the maximum time to delay between retries.
Iteration error policy
Whether to ignore an iteration error after all retries have been exhausted, or to stop the execution of the loop.
Finally
Whether to stop the workflow and return an error if the block fails, or continue to allow an error handler to run.