Its actually pretty easy:

http://pastie.org/6016681


In your case everything is executed serially.

It is  little bit more complicated when you want to mix parallel and serial 
execution.


For this case I wrote this utility:

https://github.com/kof/do

I have done a step away from Step/async libraries. They make the code harder to 
understand.

Am 01.02.2013 um 17:10 schrieb Thomas Gray <[email protected]>:

> Hi guys
> 
> Let me start out here with a disclaimer. I am a newbie to programming in 
> Javascript. It's syntax is acceptable, so I have no problem with that - it's 
> just on the structuring of Javascript especially within the Async context of 
> nodeJS.
> 
> I am at the moment trying to write a really simple RESTful API in NodeJS 
> using Mongo as a data source. I'm using express to handle the HTTP component 
> and the MongoDB library (via NPM) to handle my interaction with Mongo. I am 
> having some real troubles with how to properly structure my application. You 
> can view it as it stands here: http://pastie.org/6013517
> 
> As you will see, I am calling the user collection, then finding a user, then 
> creating a new login token, then updating the user with that login token, 
> then sending that login token back to the browser. All within one crazy 
> nested method. I've been programming in non-async languages for a while, and 
> I guess I am failing to understand the concept of how to program 
> asynchronously. The best I can come up with is to have a User object that 
> just has methods that are called within the callback of each component.
> 
> Looking at the code I have given above - how would I better structure this to 
> remove the levels of nesting, but still not have it as a procedural object 
> (ie. one method calls the next which calls the next and so on).
> 
> Maybe i'm just not understanding how to program in this environment?
> 
> Tom
> 
> 
> 
> -- 
> -- 
> 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/groups/opt_out.
>  
>  

-- 
-- 
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/groups/opt_out.


Reply via email to