Array serial join of promisey functions

18 views
Skip to first unread message

Domenic Denicola

unread,
Mar 8, 2012, 4:11:03 PM3/8/12
to <q-continuum@googlegroups.com>
I posted this over on GitHub as a documentation issue, but realized it was probably more appropriate here.

I have an array of promisey functions, and I want to call them one after the other. What's a nice, concise way to do this?

The old README [1], under "Serial Join", had some nice examples using `Array.prototype.reduce` and `Q.wait`. But `Q.wait` is dead, not that I knew what it really did in the first place.

So far the best I have is

var array = [fooAsync, barAsync];

return array.reduce(function (soFar, thisFuncAsync) {
    return soFar.then(thisFuncAsync);
}, Q.resolve());

But it feels weird having to pass in the "extra" `Q.resolve()`.

Any ideas, or is this the right way to go?

[1]https://github.com/kriskowal/q/blob/badb384c057a7a9e0441c03cfdf11d1264b2f0d0/README.md

James Burke

unread,
Mar 8, 2012, 4:23:40 PM3/8/12
to q-con...@googlegroups.com
I was trying to work out the same issue earlier today and I almost
posted about it. So a +1 for providing best guidance on how to
structure this type of code.

James

Reply all
Reply to author
Forward
0 new messages