Whatever message this page gives is out now! Go check it out!

asyncAllOf

Last update:
May 18, 2026
Waits until every Future in an array finishes. The returned Future completes when all inputs complete, or fails if any input fails.

Description

Waits until every Future in the array completes. The returned Future completes when all inputs complete, or fails immediately if any input fails.
asyncAllOf takes an array of Future objects and returns a new Future that signals completion only. It does not aggregate results. To retrieve individual results, call get() on each original Future after asyncAllOf completes. The value returned by get() on the combined Future is always null.
If an empty array is provided, the returned Future is already complete.

Returns

A Future.

Category

Asynchronous programming

Function syntax

asyncAllOf(futures)

Parameters

ParameterDescription
futuresRequired. An array of Future objects. Each element must be a Future.

See also

runAsync — creates Future

Example

Wait for three tasks, then sum their results (from product tests).

<cfscript>
    f1 = runAsync(function() { return 10; });
    f2 = runAsync(function() { return 20; });
    f3 = runAsync(function() { return 30; });

    allFuture = asyncAllOf([f1, f2, f3]);
    allFuture.get(); // wait for all

    sum = f1.get() + f2.get() + f3.get();
    writeOutput(sum); // 60
</cfscript>
      
Example 2

<cfscript>
    // asyncAllOf() - Wait for all futures to completewriteOutput("<h3>asyncAllOf() Demo</h3>");
    writeOutput("<hr>");

    // Create parallel futures
    future1 = runAsync(() => {
        local.threadName = createObject("java", "java.lang.Thread").currentThread().getName();
        sleep(300);
        return { data: "Product catalog", thread: local.threadName, time: 300 };
    });

    future2 = runAsync(() => {
        local.threadName = createObject("java", "java.lang.Thread").currentThread().getName();
        sleep(200);
        return { data: "User preferences", thread: local.threadName, time: 200 };
    });

    startTime = getTickCount();

    // wait for both together
    allDone = asyncAllOf([future1, future2]);

    // then collect results after both finish
    result1 = future1.get();
    result2 = future2.get();

    elapsed = getTickCount() - startTime;

    writeOutput("Future 1: " & result1.data & " on " & result1.thread & "<br>");
    writeOutput("Future 2: " & result2.data & " on " & result2.thread & "<br>");
    writeOutput("Total time: " & elapsed & "ms (parallel)<br>");
</cfscript>
        

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page