Skip to content
This repository has been archived by the owner on Sep 20, 2022. It is now read-only.
/ node-sleep Public archive

Synchronous sleep for your JavaScript project

License

Notifications You must be signed in to change notification settings

tbhaxor/node-sleep

Repository files navigation

Nodejs Sleep Unit Testing

As we all know that nodejs is a single threaded async language and you need to have async wrapper to execute your own sleep function. But sometimes it is required to have a synchronous sleep to make things simple and easy to understand.

This package use foreign function interface technique to call sleep and usleep functions from libc.so library.

NOTE Libc is guaranteed in macOS and Linux operating systems but not in windows. Therefore windows is not supported yet

Read More:

Installation

npm i @tbhaxor/node-sleep

yarn add @tbhaxor/node-sleep

Usage

// es6
import { sleep, usleep } from "@tbhaxor/node-sleep";

// commonjs
const { sleep, usleep } = require("@tbhaxor/node-sleep");

sleep(3); // sleep for 3 seconds
usleep(1000); // sleep for 1000 micro seconds

Licence

The project is licened under MIT License