typescript-promises

0.1.3 • Public • Published

typescript-promises

Build Status Dependency Status NPM version Views

NPM

TypeScript promises for Node.js. The following classes and function are made available to you:

  1. Deferred object
  2. Promise object
  3. when function

These are intended to match closely their respective jQuery objects; though, there are some differences. The only known differences are in cases like jQuery's deferred.done, where the documentation states, "The deferred.done() method accepts one or more arguments, all of which can be either a single function or an array of functions." In this library's case, it's just a TypeScript (...callbacks: Function[]) method signature. Contributions are welcome to fix this, but I didn't have the need to go down that road myself.

Example Usage

import promises = require('typescript-promises');
var Deferred = promises.Deferred;
var when = promises.when; // not used in this example, but handy.
 
function doSomethingAsync(): promises.Promise {
    var d = new Deferred();
    setTimeout(() => {
        // time consuming operations
        d.resolve('foo');
    });
    return d.promise;
}
 
doSomethingAsync.done(result => {
    // result === 'foo';
});

See the specs for more examples and remember, the jQuery documentation is pretty close too. The library and specs have been written to satisfy the jQuery usages.

Readme

Keywords

none

Package Sidebar

Install

npm i typescript-promises

Weekly Downloads

0

Version

0.1.3

License

MIT

Last publish

Collaborators

  • jedhunsaker