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

thenCompose

Last update:
May 18, 2026
After this Future completes normally, runs a function on the completing thread that returns another Future, and flattens the result.

Description

thenCompose is an instance method on a CFML Future. When the prior stage completes successfully, your function runs on the completing thread. The function must return another Future. The returned stage from thenCompose completes when that inner Future completes, so callers do not need nested get() calls.
This is the synchronous counterpart to thenComposeAsync. Prefer thenComposeAsync when the inner work should run on the async executor.

Returns

A new Future (flattened composition).

Category

Asynchronous programming

Function syntax

future.thenCompose(function)

Parameters

ParameterDescription
functionRequired. A function that accepts this stage’s result and returns a Future.

Example

Chain a second async task without nesting futures manually.

<cfscript>
    future = runAsync(function() { return 5; });
    composed = future.thenCompose(function(x) {
        return runAsync(function() { return x * 10; });
    });
    writeOutput(composed.get()); // 50
</cfscript>
      

See also

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