Skip to content

Implementation of sleep, usleep and msleep for Node.js

Notifications You must be signed in to change notification settings

NewHR/nodejs-sleep

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

Implementation of sleep, usleep and msleep for Node.js

Warning(!) These calls will block execution of all JavaScript by halting Node.js' event loop!

Don't use in express and server application only if you understand why you need it.

Mainly useful for debugging.

Usage

Sleep process for seconds

const sleep = require('./sleep').sleep;

for (let i=0; i<10; i++) {
  console.log(+new Date);
  sleep(1);
}

Sleep process for milliseconds

const sleep = require('./sleep').msleep;

// Sleep 1000ms = 1s
for (let i=0; i<10; i++) {
  console.log(+new Date);
  sleep(1000);
}

Sleep process for microseconds

const sleep = require('./sleep').usleep;

// Sleep 1000000ms = 1s
for (let i=0; i<10; i++) {
  console.log(+new Date);
  sleep(1e6);
}

About

Implementation of sleep, usleep and msleep for Node.js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published