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

thenApply (Future method)

Last update:
Jun 9, 2026
After this Future succeeds, runs your function on the thread that completes the Future and returns a new Future with the transformed value.

Description

thenApply is the synchronous counterpart to thenApplyAsync. The callback runs on the completing thread, not on the async executor. Use it for fast, non-blocking work that should stay on the same thread.

Returns

A new Future.

Category

Asynchronous programming

Function syntax

future.thenApply(function)

Parameters

ParameterDescription
functionRequired. A function that takes the previous result and returns the next value.

See also

Example

Mix sync and async stages in one chain (from product tests).
future = runAsync(function() { return 5; })
    .thenApply(function(x) { return x * 2; })
    .thenApplyAsync(function(x) { return x + 5; })
    .thenApply(function(x) { return x * 2; })
    .thenApplyAsync(function(x) { return x + 10; });
writeOutput(future.get()); // 40

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