volojs/volo — comment on commit 9b2ad0b2ec3999fb079ed6213138499fc8eb1a7e
File: dist/volo.js line 4463
By kriskowal:

On Mon, Jan 9, 2012 at 1:37 PM, James Burke

wrote:
> Ah, great, I'll look at Q.call() to avoid the Q.defer().resolve() junk. It would be great if there was a promises recipe book or something like a graduated tutorial. If you know of one that would be great, but I can appreciate it would take quite a bit of effort to produce.

The README.md is a bit of a sad attempt at such a tutorial, or at
least the framework. Teaching promises, I think, is a lot harder than
learning them. I’ll have to spend more time on this.

> I appreciated the serial and parallel discussion in the q readme, but for the serial case I have, I did not have the same amount of work I could call on an item in an array, but more that I wanted to construct a series of different operations/work that each depended on the previous operation resolving, and I wanted to inject an intermediate rejection handler to do some cleanup, but then also reject the top-most deferred with the rejection. So, some rejection handlers, but only at certain points. I also had a step in there that was optional/depended on inputs.
> So QQ.step() looked interesting, but I was not sure how to do the rejection work in that case.

As it turns out, QQ.step is superfluous and your chains of then calls
do the same job. If an error occurs in any step of the chain and is
not handled downstream, it just keeps getting forwarded until some
.then or .fail call provides a callback to handle the rejection. The
errback is just like a catch block: it can either fix the problem,
wrapping things up so the state is consistent when it’s done, or it
can do some handling and rethrow the error. You can even use "throw"
in the errback.

> Anyway, thanks for the guidance and looking at the bad code. I'm still very new to advanced promise usage, still trashing about in the code.

The code isn’t bad — for what it’s worth, you probably won’t need much
more than what you’re already using. ".then" is a very powerful tool
by itself. ".call" is good for starting chains and will save some
time. ".all" will make some common patterns really simple to do right.
".fail" is just sugar. Disciplined use of ".end" to terminate chains
that don’t get returned will save you some time. ".defer" is strange
because on one hand, it’s the first thing most folks will learn about
a promise library, but it’s also the least frequently needed. Maybe
this sequence is a good framework for a graduated tutorial.