Async programming; future and promises

h/t Sean Corfield in the Lucee Google Group

We’ve had thread in CFML for a long time now but it’s really only suitable for running procedural (side-effecting) code in background threads. It’s not really very good for async programming in general.

I think it would be a really nice enhancement to the Lucee dialect to fully support futures and promises.

There are several implementations out there in various languages so there are quite a few specific models to choose from.

For those not familiar, the general idea is something like this:

var a = future( some expression );
var b = future( some other expression );
var c = a.get() + b.get();

This spins off some expression and some other expression to execute in other threads, but immediately returns a reference to the “future” value. Calling get() on the future will block until the value is available (or return immediately if the expression has already completed). Calling get() multiple times will just return the computed value (it’s cached for the life of the reference).

Promises are similar but rely on other code to compute the value:

var a = promise();
var b = promise();
// maybe in another thread:
a.deliver( 42 );
// maybe in yet another thread:
b.deliver( 13 );
var c = a.get() + b.get();

Like futures, the get() call will block until the promise has a value.

Both of these allow complex operations — time-consuming ones — to be broken down and easily run concurrently while maintaining much clearer code than trying to manage a whole bunch of thread { … } statements assigning values back and forth.

Fancier features allow for completion callbacks, error callbacks, timeouts (and timeout callbacks), etc.

Sean Corfield – (904) 302-SEAN
An Architect’s View –


Tracking in JIRA at:

Add futures and promises to the Lucee dialect

Just throwing this out there, I got bored so whipped up a Lucee 5 extension that brings in Javascript-style Promises over at


Lucee now has support for runAsync

1 Like