Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

async_future.coffee

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async_future.coffee

An asynchronous future class, written in CoffeeScript.

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

AsyncFuture.coffee 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.

Installation

npm install async_future.coffee

Usage

user_future = new AsyncFuture load_user, user_id

# Do something else now.

user_future.get (user) ->
  console.log "This user was loaded in the background, and it didn't hurt: #{user}"

Examples

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.

1_waits_for_results.coffee: Demonstrates how Futures wait until they receive the results before they call the callback method given.

2_has_results.coffee: Demonstrates how Futures hold on to the result of the parallel operation until it is requested by their get method.

Development

To run the tests:

$ npm test

FAQs

Package last updated on 17 Sep 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc