On Aug 20, 2014, at 4:27 PM, Aria Stewart <[email protected]> wrote:
> 
> The while loop is blocking -- it spins, doing useless work and NOTHING else 
> until it expires. Your entire node process is hung during this time, so both 
> requests "wait".
> 
> Delaying with:
> 
>  setTimeout(function() {
>       db.users.find({}, function(err, users) {
>              callback(users);
>        });
> }, long ? 5000 : 0);
> 
> would do what you want, and yield the event loop in the mean time. 
> 
> Node only does one thing at a time -- setTimeout is "call me when this time 
> has passed; do what you need to until then"; while (stuff) is "do nothing but 
> this until...."

In addition, note that you are not handling errors. By convention, a callback 
should accept err as its first argument, which will be null if there is no 
error.

        db.users.find({}, function(err, users) {
               callback(err, users);
         });

Or more simply:

        db.users.find({}, callback);

Also by convention, a callback should be the last argument.


-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/66D28D4F-9697-447F-93CA-C1D9060C7A12%40ryandesign.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to