node package manager
We need your input. Help make JavaScript better: Take the 2017 JavaScript Ecosystem survey » Build status

An asynchronous Future class, written in CoffeeScript.

What are Futures?

Futures provide a simple API for running parallel operations in the background, and pick up their results at a later time (in the "future").

By encapsulating the management of parallel operations, Futures allow to create sophisticated parallel application behavior using a simple, single-threaded programming style. This library provides Futures asynchronous interface, as is typical in Node.js environments. Futures support Node's asynchronous, event-driven flow patterns very naturally.

Here is an example:

  1. Start a parallel operation that performs a long-running method, store it in a Future.
  2. Do other things in your main thread. Take your time.
  3. When done with (2), pick up the result of the parallel operation from the future created in (1).
  4. Both long-running operations - (1) and (2) - have run in parallel, but were coded like a single-threaded application.


npm install


user_future = new AsyncFuture load_useruser_id
# Do something else now. 
user_future.get (user) ->
  console.log "This user was loaded in the background, and it didn't hurt: #{user}"


The directory /examples contains a number of usage examples that visualize better how futures work. You can run them simply by doing coffee [filename] in the terminal.

Delay Futures

The directory /examples/delay_future demonstrates how futures operate on the time line. Demonstrates how Futures wait until they receive the results before they call the callback method given. Demonstrates how Futures hold on to the result of the parallel operation until it is requested by their get method.


To run the tests:

$ npm test