task_all

task_all

task_all

Function

Waits for a set of background tasks to complete and returns the success result of each task in the order entered. task_all(tasks) is a synchronous combination waiting function and will not cancel unfinished tasks.

Syntax

Parameters

ParametersTypeRequiredDefault valueDescription
tasksArrayYesNoneArray of Tasks to wait for.

Return value

TypeDescription
ArrayWhen all tasks are successful, the result array is returned in the input order; an empty array returns [].

If any task fails throw or fails normally, task_all() waits for all tasks in the input to complete, then selects the first non-successful result in the order of input: throw will rethrow, and a normal failure returns a runtime error.

Example

Notes

  • The parameter must be an array, and all array elements must be Task.
  • task_all([]) returns the empty array [].
  • Tasks are already executed concurrently when they are created. task_all() Waiting for results in the order of input will not turn task execution into serial.
  • task_all() blocks the current execution flow; should be used with caution in web request hot paths.
  • Still running tasks will not be forced to be canceled when other tasks fail.