#promise-ts
![Views](https://sourcegraph.com/api/repos/github.com/jedmao/promise-ts/counters/views-24h.png)
![NPM](https://nodei.co/npm/promise-ts.png?downloads=true)
Promises for Node.js, written in TypeScript and distributed in JavaScript, along
with a TypeScript definition file at the root (promise.d.ts). These promise classes
and functions "mostly" behave like jQuery promises, so you can refer to
jQuery documentation for more detailed information.
The following classes and function are made available to you:
- Deferred object (jQuery doc)
- Promise object (jQuery doc)
- when function (jQuery doc)
The only known differences between the jQuery counterparts 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
TypeScript
import promise = require('promise-ts');
var Deferred = promise.Deferred;
var when = promise.when;
function doSomethingAsync(): promise.Promise {
var d = new Deferred();
setTimeout(() => {
d.resolve('foo');
});
return d.promise;
}
doSomethingAsync.done(result => {
});
JavaScript
var promise = require('promise-ts');
var Deferred = promise.Deferred;
var when = promise.when;
function doSomethingAsync() {
var d = new Deferred();
setTimeout(function() {
d.resolve('foo');
});
return d.promise;
}
doSomethingAsync.done(function(result) {
});
See the specs for more examples. The library and specs have both been written
to satisfy the jQuery usages.
License
MIT © Jed Mao
![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/jedmao/promise-ts/trend.png)