pacta
This is an implementation of algebraic Promises in
node.js having been convinced by James
Coglan
and Aanand Prasad.
Pacta's promises can be used as the following algebraic structures:
Note that Pacta does not handle errors or the concept of a failed promise as
yet.
See the test
suite for more
information.
Usage
var Promise = require('pacta').Promise;
var p = new Promise();
setTimeout(function () {
p.resolve('Foo');
}, 1000);
var p2 = new Promise();
setTimeout(function () {
p2.resolve('bar');
}, 500);
var p3 = Promise.of('baz');
p.map(console.log);
p.map(function (x) {
return x + '!';
}).map(console.log);
p.concat(p2).concat(p3).map(function (x, y, z) {
console.log('p says: ' + x);
console.log('p2 says: ' + y);
console.log('p3 says: ' + z);
});