Project Description

A self-contained JavaScript (via TypeScript) implementation of the Promises/A+ 1.1 specification (and Deferred provider), suitable for inclusion in larger libraries and projects. This implementation provides the core functionality required to leverage asynchrony / tasks / futures / promises within any project or library (including browsers and Node.js), facilitating simpler, more expressive, more maintainable code.

Features

  • A single TypeScript module and / or JavaScript IIFE that can be easily integrated into other projects or referenced by them.
  • No external dependencies.
  • Lightweight: ~6Kb minified, ~1.6Kb minified & GZIPped
  • Fully-documented TypeScript and JavaScript code, both inline and online.
  • A Node.js module published on npm.
  • Conversion methods to quickly turn synchronous, asynchronous, and Node.js-style asynchronous methods into Promise-generating methods. See the Convert class / namespace for more details.
  • A quick and convenient way to turn all Node.js and Node.js-like asynchronous methods into Promise-generating methods. See the Convert.objectNodeAsyncMethods and Convert.fromNodeAsyncMethod method documentation for more details.
  • Uses the best scheduling mechanism available, whether it be setImmediate, setTimeout, or a custom implementation.
  • A convenient MIT license.

Why?

Whatever your terminology choice, the application of promises / futures / tasks / asynchronous constructs to most programming endeavors produces code that is more expressive, more responsive, more efficient, and more maintainable. Utilizing a simple asynchrony pattern allows the creation of libraries that express events and the production of future values without the need for manually-created, repetitive, fragile constructs. The goal of this project is to provide a "pluggable," bundling-ready, well-documented, testable, streamlined JavaScript component that others can use as a composition block in their efforts, modifying it to suit their specific needs. In even small projects, the code reuse provided will quickly offset the small library size.

Though jQuery and other libraries provide promises and deferred execution options, they are but small components of larger systems that require the entire library to be present, creating a rather hefty dependency and potentially-long page load times. In contrast, this library targets the light-weight, "initial loading" scenarios that bridge the gap between "document loading" and library readiness. Moreover, unlike many other implementations of promises, which implement their then methods as executing callbacks immediately if the instance is already complete, all callbacks in this implementation conform to the specification and are scheduled for later execution, providing a fast, consistent flow of execution.

Suggestions for improvement are always welcome and will be integrated as-appropriate.

Tests

Automated testing has been rigorously and thoroughly applied to this project using these tests (all of which pass):

  • A wrapper that applies the full Promises/A+ 1.1 test suite.
  • A set of QUnit tests that provide cross-browser testing for Promise functionality, Promise extensions, and conversion methods.

Where They're Used

Optionally, let me know what projects you've developed using this library and I'll feature them on the project page. It's always nice to see where a project gets incorporated...

Last edited Mar 21, 2014 at 11:00 PM by CommanderQ, version 21