Sunday 24 February 2019

Is exist a way to put NodeJS in sleep mode?

I'm building a chat app that sync with my remote database every 180 seconds, I'm wondering how would you put the function in sleep mode when the server is free of any request anymore, hence free of need to sync with the remote database?​I have thought to the following solution-mockup inspired from this discussion on stackoverflow :function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } async function demo(time) { console.log('Taking a break...'); await sleep(time); console.log('Two seconds later'); } My thread { ... } demo(); // restart the sleepMode's timeout How would you release a such function in your code?Any hint would be great,thanks

Submitted February 24, 2019 at 09:04AM by JoonDoe

No comments:

Post a Comment