It's worth noting we are <i>very</i> close to finishing up a 1.1 revision of the spec, which clarifies a few things mainly around how promise libraries interoperate with each other's promises. You can find the work in our master branch (as opposed to gh-pages):<p><a href="https://github.com/promises-aplus/promises-spec" rel="nofollow">https://github.com/promises-aplus/promises-spec</a><p>Including a changelog:<p><a href="https://github.com/promises-aplus/promises-spec/blob/master/changelog.md" rel="nofollow">https://github.com/promises-aplus/promises-spec/blob/master/...</a><p>And the issues still open versus closed in the 1.1 timeframe are at<p><a href="https://github.com/promises-aplus/promises-spec/issues?milestone=2&page=1&state=open" rel="nofollow">https://github.com/promises-aplus/promises-spec/issues?miles...</a><p>We were hoping to do a revision of the website's look at the time of the 1.1 release as well, mainly adding links to additional resources in the repository (like the implementations list, credits, etc.). A bit sad that we haven't moved fast enough to finish that before making the front page of Hacker News!
I have just started doing development in Node.js. Originally using the excellent caolan/async library (<a href="https://github.com/caolan/async" rel="nofollow">https://github.com/caolan/async</a>) for handling synchronous situations. Now started moving towards Promises but finding it quite hard to locate any "Promises for Dummies" type guide. Most of the libraries like "q" etc (<a href="https://github.com/kriskowal/q" rel="nofollow">https://github.com/kriskowal/q</a>) just give you a list of functions to use and related syntax but I have yet to come across a guide that goes into detail as to exactly how and why you use certain functions.<p>I am kind of figuring things out as I go along but if anyone here can point me to such guides, I would be most grateful.
My beef with JS Promises (uppercase "P") is that, as a programming idiom, I prefer <i>once I have X, Y and Z, do something with X, Y and Z</i> over <i>get X, then get Y, then get Z</i>. In the former case, the provisioning logic is a separate concern; it could be done in parallel, serially, or via some combination of both. In the latter case, it's inherently serial.<p>I wrote an alternate implementation of promises in JS (lowercase "p") that uses the former approach: <a href="https://github.com/greim/await.js" rel="nofollow">https://github.com/greim/await.js</a>
The great thing about Promises/A+ is that it's so small. I have implemented it in 375 bytes, and was even able to add two convenience functions: <a href="https://github.com/timjansen/PinkySwear.js" rel="nofollow">https://github.com/timjansen/PinkySwear.js</a>
I gave a talk at JSConf US 2013 about the genesis of this spec, and how I believe it plays into the future of open, developer-driven APIs for the web platform. I hope the video is up soon, but until then, the slides are at <a href="http://www.slideshare.net/domenicdenicola/boom-promisesa-was-born" rel="nofollow">http://www.slideshare.net/domenicdenicola/boom-promisesa-was...</a>
Maybe I'm missing something, but I find C#'s async/await much more intuitive (not having written any C# and currently working on a pet project using promises with Node and Q).<p>My issue with promises is that I find myself working around the API/language when I actually want synchronous code. My app calls a JSON API and then writes the results to three tables (in sequence). In "normal", blocking code:<p><pre><code> results = getResults(); writeTable1(results.foo); writeTable2(results.bar); writeTable3(results.baz);
</code></pre>
Using Node and Q:<p><pre><code> db.load().then(()-> setupDB(db)).then(()-> collectData(db)).done()
</code></pre>
In which setupDB() returns a chain of three promises and collectData, which loops through the results and attach a new promise to the chain in order to return a chain of `n` promises.<p>Are these just growing pains of learning a new paradigm or am I using the wrong tool for the job?<p>Can someone point me to any projects that actually use promises?
I wrote a library a while ago that nearly fulfills this entire spec. I've added/changed things that I thought were more intuitive.
<a href="https://github.com/kolodny/wttt" rel="nofollow">https://github.com/kolodny/wttt</a>
> 3.2.1.1 If onFulfilled is not a function, it must be ignored.<p>This is idiomatic JS I guess, but it bugs me to bits. IMO the parameter should be a function or it should be null; anything else should throw an error.
Thanks for this discussion... after reading Domenic's slides, watching his talk, and going through the questions here and on the gist, I've filed a bug to try to move Enyo's async implementation to promises after our next release. (<a href="https://enyojs.atlassian.net/browse/ENYO-2700" rel="nofollow">https://enyojs.atlassian.net/browse/ENYO-2700</a>) Currently, our code is more like the jQuery 1.5 implementation, but it really lacks the nice error semantics that Promises/A+ has.
Promises are coming of age too late, and still have unsolved fundamental issues.<p>Meanwhile, ES6 generators are coming to node v0.12, already in FF and soon to be in Chrome; <i>that</i> is a whole different game.