Because forEach uses a function to call back, but is not asynchronous.  A 
function not doing I/O can choose when it calls your function.  

forEach takes the easy path and just calls its callback in a loop one after 
another. 

Angelo Chen <angelochen...@gmail.com> wrote:

>one confusing thing for newbies like me:
>
>exports.get_list = function ( cb) {
>               rclient.smembers("list", function(err, members) {
>                       members.forEach(function(member){
>                               console.log(member)
>                       })
>                       cb(null, 'lst')
>               })
>}
>
>the function(member) for 'forEach' is callback, right? then why,
>cb(null,'lst') will wait until the loop is over?
>
>
>
>On Mar 20, 5:18 pm, Oliver Leics <oliver.le...@gmail.com> wrote:
>> On Tue, Mar 20, 2012 at 8:47 AM, Bruno Jouhier <bjouh...@gmail.com> wrote:
>>
>> >     var next_id = rclient.incr("next_id", _);
>>
>> > This code is asynchronous. And the underscore marker indicates where the
>> > code may yield. So nothing's hidden and the execution model is the same as
>> > with async callbacks: non blocking, single threaded event loop, non
>> > preemptive.
>>
>> The underscore "_" in the above example IS the callback, so it is
>> still using callbacks. It is only abstracting them away.
>
>-- 
>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 nodejs@googlegroups.com
>To unsubscribe from this group, send email to
>nodejs+unsubscr...@googlegroups.com
>For more options, visit this group at
>http://groups.google.com/group/nodejs?hl=en?hl=en

-- 
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 nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to