If you reference the npm sleep module, readme indicates that sleep block execution. So you are right - this is not what you want. Instead, you want to use setTimeout , which does not block. Here is an example:
setTimeout(function() { console.log('hello world!'); }, 5000);
For those who want to do this using es7 async / await, this example should help:
const snooze = ms => new Promise(resolve => setTimeout(resolve, ms)); const example = async () => { console.log('About to snooze without halting the event loop...'); await snooze(1000); console.log('done!'); }; example();
David Weldon Nov 19 '12 at 6:01 2012-11-19 06:01
source share