typescript-promises
v0.1.3
Published
TypeScript promises for Node.js.
Downloads
5
Readme
#typescript-promises
TypeScript promises for Node.js. The following classes and function are made available to you:
- Deferred object
- Promise object
- 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.