Parallel Command
Run a series of commands in parallel. The Parallel
command starts running all child commands simultaneously. The Parallel
command finishes when all the defined child commands have finished. When the Parallel
command stops, all running commands stop.
Properties
The Parallel
command has the properties shown in the following table, in addition to the common command properties. Set the type
property to Parallel
.
In the following table, the "Default" column shows "Required" for properties that must have a value for the command to run. Otherwise it displays the default value, which might be none.
Property | Type | Default | Description |
---|---|---|---|
|
Array of commands |
Required |
An unordered list of command to run in parallel. |
|
Array |
[] |
A list of data to map against the commands. |
In fast mode, the parallel command runs all of the sub-commands in parallel, but without delays (giving a net zero duration).
commands
An un-ordered array of commands to run in parallel. Once all commands have finished running, the Parallel
command finishes. The delay
value set for the Parallel
command is added to the delay
value set for each of the commands in the array. In the following example, the first SendEvent
command starts after 1500 milliseconds, and the second SendEvent
command after 750 milliseconds, which means the second SendEvent
command starts before the first.
{
"type": "Parallel",
"delay": 500,
"commands": [
{
"type": "SendEvent",
"delay": 1000
},
{
"type": "SendEvent",
"delay": 250
}
]
}
data
The array of data to iterate over. When the data
array contains data, the Parallel
command iterates over that array and creates a new Sequential
command for each value in the array. Each new Sequential
command contains the commands from the original commands
property. This is similar to the way data array inflation works for multiple-child components. The resulting Parallel
command then runs all these Sequential
commands at the same time.
For example, the following Parallel
command contains two commands in commands
and two strings in the data
array.
{
"type": "Parallel",
"data": ["item1", "item2"],
"commands": [
{
"type": "CustomCommand1",
"item": "${data}"
},
{
"type": "CustomCommand2",
"item": "${data}"
}
]
}
This command expands into a Parallel
command that contains one Sequential
for each of the two items in data
. The final command to run is therefore the following.
{
"type": "Parallel",
"commands": [
{
"type": "Sequential",
"commands": [
{
"type": "CustomCommand1",
"item": "item1"
},
{
"type": "CustomCommand2",
"item": "item1"
}
]
},
{
"type": "Sequential",
"commands": [
{
"type": "CustomCommand1",
"item": "item2"
},
{
"type": "CustomCommand2",
"item": "item2"
}
]
}
]
}
During iteration, the data-binding context extends to include the properties shown in the following table.
Name | Description |
---|---|
|
Data assigned from the data array property. |
|
The 0-based index of the current data item. |
|
The total number of data items in the data array. |
These properties are set when the data
array property contains at least one item.
Parallel example with the data array
The following example displays a list of items. The button defines a Parallel
with three SetValue
commands to select a random color from a list, change the color of an item to the random color, and then change the text of the item to the name of the color. The Parallel
sets the data
array to the same list of items displayed in the Sequence
.
When the command runs, each item in the list first changes color, then changes its text. The items in the list all update at the same time.
For a similar example in which the list items update one after another, see Sequential example with the data array.
Related topics
Last updated: frontmatter-missing