nodejs-system-sleep
nodejs-system-sleep copied to clipboard
not waking up after sleep
in a while loop, it's not waking up after 2nd time
const express = require('express')
const sleep = require('system-sleep')
const app = express()
app.listen(3000, () => {
while(true){
console.log("in a while loop")
sleep(5000)
}
})
I am not exactly sure why this happens. It has something to do with Express. Running it on my machine, the console.log call runs 5 times. If you put it outside the callback function of app.listen, it works fine.
app.listen(3000, () => {
//
})
while (true) {
console.log("in a while loop")
sleep(5000)
}
When I put it in a separate function like this:
const express = require('express')
const sleep = require('system-sleep')
const app = express()
const sleeper = () => {
while (true) {
console.log("in a while loop")
sleep(5000)
}
}
app.listen(3000, () => {
sleeper()
})
it indeed stops after 2 times. I don't understand why and any comments are very welcome.