I'm hoping some folks can take a few minutes to review some code I was working on today.
https://gist.github.com/1115202
Essentially, I'm doing a lot of work in Node.js at the moment and I'm a big fan of Promises.
Since 99% of the work that I'm doing involves performing several asynchronous actions and then parsing the results, I wanted something a little simpler and more light-weight that some of the other Promise/Deferred/Futures libraries that are out there.
My aim with this is to have a simple when().then() format without having to instantiate a new Promise inside each function.
The usage is like this:
when(
function(){ this.pass(1); },
function(){ this.pass(2); }
)
.then(function(results){
console.log( results );
});
In the Github gist I've linked to above, there are use cases near the bottom. Test case 1 uses timeouts, the 2nd test case uses several async http requests in Node.js and logs the total results at the end when all 3 have finished.
I'd love to hear any opinions good or bad, recommendations on how to make it better, etc.
after
return value twice, or is that not a worry? I mean the scenario of that happening is highly unlikely. \$\endgroup\$after
in a buggy manner then that's a bug you should fix. \$\endgroup\$