Rsvp.js
github.com
github.com
Check out "Q" as well: https://github.com/kriskowal/q
There are adapters for many of Node's APIs (and it's easy to create more)
https://github.com/kriskowal/q-io
Currently, only RSVP and Q pass the entire suite.
My requirements matched closely with the promises test-suite recently released, including a requirement that all promises be delivered asynchronously and efficiently if possible (`when` does not satisfy this requirement).
I could not find any existing small, embeddable libraries that satisfied all of these requirements.
A break down of pros and cons for each would be really useful, and I'm not sure anyone has done that already (at least I can't find any after a quick search).
Q: Too monolithic
promise-stream: inadequate chaining support and node-specific
when.js: synchronous delivery, much larger API surface area than Promises/A
For what it's worth, promise-tests was written by Domenic Denicola, a contributor to Q, who seemed happy to have a lightweight entrant that implemented promises correctly.
The readme in the repository has some good discussion around the different features you mention here, but it would be really interesting to see a discussion around the design of this library in counterpoint to the other options available. Some other time maybe!
With regards to the promise-tests, I think multiple implementations validate a concept, and a set of tests for a specification is much more useful when multiple implementations can pass it. If the specification is extended you have multiple implementations to compare the impact against, and if the implementations' behaviour differ in notable ways then you expose holes in the test suite.
Multiple implementations of a specification, particularly when they all pass a common test suite, is a good thing.
function (error) {
// handle error
}
What do you do there? Exit the process? How to recover and continue from some critical point? Can you retry some part of the action? Can you try some alternative actions if something fails?So I felt we can do better and .... surprise .... wrote my own heavy weight (1 kloc) library that provides a richer-than-usual set of composeable async primitives emphasizing error management including recovery, restarts, alternatives, etc.
So, here is yet another "wheel" :)
Although it's obviously not built in favor of any particular JS framework or environment, it may entice me to give Node.JS another shot in the future with implementing RSVP.
Promise.when(func(), function(val) {
alert(val);
});
So if `func` returns a normal value, the cb runs immediately. If it returns a promise, the cb runs on fulfillment.Sometimes, it's just better to give your functions names, and pull them out.
RSVP.js looks nice. Also, I like jQuery's implantation of promises specifically with the ajax function.
Promises are a different abstraction of async operations. I am still trying to wrap my head around them fully, but one of the advantages seems to be writing code that looks a little more sequential.
I'd be more interested in how it compares to using postMessage which, from testing, is definitely a lot faster than setTimeout (like fast enough to be worth switching to if available).