I probably sounded a bit weird yesterday. A quick explanation: I've been
advertising a bit loudly for my own solution on this mailing list some time
ago. I'm trying to be a bit more discrete these days.
But just for the fun of it, I'll do it one more time. Here is what your
last example becomes:
var value4 = step4(step3(step2(step1(_), _), _), _);
So if you are ready to go with a little (transparent) preprocessor, this is
what you can expect your code to look like.
A quick comment on Alexey's list (callback hell, statemachine hell, etc.):
If you pick the right tools, the last 3 solutions (preprocessor,
generators, fibers) become almost equivalent: they all give you plain
synchronous code with robust error handling, meaningful stack traces and
good debugging experience (thanks to sourcemaps). What matters then is
performance and here it depends on your code patterns.
Bruno
On Saturday, April 19, 2014 6:28:42 AM UTC+2, Kevin Burton wrote:
>
> Thank you very much for all the replies. This has been most enlightening.
> Based on all of the replies and my situation I would like to explore
> Promises more. I think I understand the basic idea behind promises but lack
> specific implementation details. Does anyone have a good example of using Q
> and Node.js like the readme indicates:
>
> ```javascript
> step1(function (value1) {
> step2(value1, function(value2) {
> step3(value2, function(value3) {
> step4(value3, function(value4) {
> // Do something with value4
> });
> });
> });
> });
> ```
>
> With a promise library, you can flatten the pyramid.
>
> ```javascript
> Q.fcall(promisedStep1)
> .then(promisedStep2)
> .then(promisedStep3)
> .then(promisedStep4)
> .then(function (value4) {
> // Do something with value4
> })
> .catch(function (error) {
> // Handle any error from all above steps
> })
> .done();
> ```
>
> I get lost with denodify and deferred which the above simplification
> doesn't address. Any clarification for the newly initiated?
>
> Thank you.
>
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.