Closed RifeWang closed 7 years ago
the doc.map()
call is calling asynchronous functions that won't update the count variable until some time in the future. The while loop is executing synchronous, so this is expected.
I'm going to go ahead and close as this is not a bug in core. If you have more questions, please open an issue at https://github.com/nodejs/help/issues. Thanks!
@evanlucas I still don't understand , althoungh the while loop is executing synchronous , but when the count++ finished in asynchronous functions , I think it will go continue not block .
that while loop will never end because it blocks those asynchronous functions' callbacks from being executed. You would need to wait until all of the callbacks have been executed before calling res.json(). It would probably be easier to use a flow control library like async
when doing this though
I used a while loop and mongoose in mycode : let's see the care here part .
I find that in the while loop , the code block and aways log 0 , this means
count++
doesn't work , but when i delete the while loop part ,count++
is work . Is this the mongoose problem? i don't kown . OR something bug when use the while loop in node.js's event-loop?