Description

A function that returns a Future object. For more information, see Asynchronous programming in ColdFusion.

Returns

A Future object.

Syntax

RunAsync()
RunAsync(UDFMethod function)
RunAsync(UDFMethod function, long timeOut)

History

New in ColdFusion (2018 release).

Parameters

Parameter Required/Optional Description
function Optional Closure function that returns a Future object, which holds the result of execution, status, and so on.
timeOut Optional Timeout in milliseconds.

Examples

To run a function asynchronously and get a result,

<cfscript>
             //To run a function asynchronously and get the result
             future = runAsync(function(){
                           return "Hello World!";
                      });
             result = future;
             writeOutput(result.get());
</cfscript>

To run a function asynchronously after the completion of another function,

<cfscript>
             future = runAsync(function(){
                    return 5;
             }).then( function(input){
                    return input + 2;
             });
             result = future.get(3); // 3 is timeout(in ms)
             writeOutput(result);
</cfscript>

Using an error handler,

<cfscript>
             future = runAsync(function(){
                           return 5;
                      }).then(function(input){
                           return input + 2;
                      }).error(function(){
                           return "Error occurred.";
                      });
             result = future.get();
             writeOutput(result);
</cfscript>

To chain,

<cfscript>
       func = function() { 
             return "Hello World!";
             };
        thenfunc = function(input) { 
             return input & "It is a beautiful day!";
             };
        future = runAsync(func).then(thenfunc);
        writeOutput(future.get());
   </cfscript>

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy