
Promises/A+ - understanding the spec through implementation - shawndumas
http://modernjavascript.blogspot.com/2013/08/promisesa-understanding-by-doing.html
======
AdrianRossouw
I feel like promises are slowly becoming more accepted and widely used through
the javascript community.

I know I didn't immediately see the point of them, and had to sit down and
learn to use them properly before I was convinced.

~~~
jbmartin
I found Async Javsacript by Trevor Burnham super helpful for learning how use
promises properly. However, it doesn't cover the javascript implementation of
a promise (uses jQuery), so this is a nice blog post complementing that
material.

------
tieTYT
What's a promise? This article seems to assume you know that when you start
reading. Here's my understanding: Sometimes in code you get into callback
hell. A callback calls a callback calls a callback. Your code starts to grow
horizontally more than vertically like this:

    
    
      callback1
        callback2
          callback3
          callback3ReactionToFailure
        callback2ReactionToFailure
      callback1ReactionToFailure
    

As a result, the code is hard to read because it doesn't flow sequentially.

Promises are a solution to that problem. They let you take something that
would be callback hell and write it sequentially.

Keep in mind it's the blind leading the blind here. I just learned this term a
month ago. Please correct me if I'm wrong.

That said, I found [http://promises-aplus.github.io/promises-
spec/#terminology](http://promises-aplus.github.io/promises-spec/#terminology)
to be more informative than the article itself (no offense)

------
ville
Another nice resource on implementing promises are the design documentation on
Q (promise library) repository:
[https://github.com/kriskowal/q/blob/master/design/README.js](https://github.com/kriskowal/q/blob/master/design/README.js)
(HN discussion:
[https://news.ycombinator.com/item?id=4767941](https://news.ycombinator.com/item?id=4767941))

------
chenglou
Does anyone know if ES6's `yield` operator can potentially satisfy most of the
goal of promises? It's still confusing after a while.

------
jbmartin
jQuery loosely follows the Promises/A spec [1], so Q.js [2] might have been
better choice.

[1] [http://domenic.me/2012/10/14/youre-missing-the-point-of-
prom...](http://domenic.me/2012/10/14/youre-missing-the-point-of-promises/)
[2] [http://documentup.com/kriskowal/q/#](http://documentup.com/kriskowal/q/#)

~~~
SeanDav
I disagree. I would rather see examples of Promises in pure Javascript. It is
the more general approach and not everyone uses jQuery.

~~~
jbmartin
My mistake. I thought the blog post was about using jQuery. I totally agree
with you.

------
islon
you can use core.async [1] on clojurescript right now to mitigate callback
hell (or if you love go aync/channels)

[1] [http://www.infoq.com/news/2013/07/core-
async](http://www.infoq.com/news/2013/07/core-async)

