javascript - why sleep in nodejs doesn't work as expected -


i use library sleep inside loop, loop this

while(condition){     usleep(1)     while(condition){         usleep(1)         // ... stuff (sync)     } } 

althought i'm sleeping 1us, loop never terminate take very long time, when remove sleep statement, run , done.

i'm trying sleep make cpu calms down , not use 100% server keep accepting other requests!

using settimeout inside loop not idea, because settimeout async.

i thought using recursion, i'm afraid slow, i'm iterating arount 100000

sleep blocks current thread, not try accept other requests. can try sleep-async job.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -