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

applyToEither

Last update:
May 18, 2026
When either this Future or another Future completes normally first, maps the winning value on the completing thread.

Description

applyToEither is an instance method on a CFML Future. You pass a second Future to race. Whichever stage completes successfully first supplies its value to your function. The function runs on the completing thread and returns a mapped value. The method returns a new Future for that mapped outcome.
This is the synchronous counterpart to applyToEitherAsync. Typical uses include redundant sources or hedged requests where the fastest success wins.

Returns

A new Future.

Category

Asynchronous programming

Function syntax

future.applyToEither(other, function)

Parameters

ParameterDescription
otherRequired. The other Future to race.
functionRequired. A function that accepts the first completed value and returns the transformed value.

Example

Process whichever string finishes first.

 <cfscript>
    f1 = runAsync(function() { return "fast"; });
    f2 = runAsync(function() {
        sleep(1000);
        return "slow";
    });
    either = f1.applyToEither(f2, function(x) {
        return x & "_processed";
    });
    writeOutput(either.get()); // fast_processed
</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