Pause the execution the specifed number of milliseconds (Browser and Node).

Usage no npm install needed!

<script type="module">
  import jsSleep from 'https://cdn.skypack.dev/js-sleep';


NoDependencies Browser Node

Browser & Node, ES7 sleep()

Pauses the execution (without freezing the Browser/thread) the requested ammount of milliseconds.

The implementaton in based in the native Promises, and requires the usage of await.

asymc function main(){
    // some code...
    await sleep(1000);
    // continue execution...

Package distribution networks :

In browser enviroment you can include this library using the jsdelivr CDN ...

<script src="https://cdn.rawgit.com/colxi/js-sleep/master/js-sleep.js"></script>

If you are in the NodeJs enviroment, can install and import the package via:

$ npm install js-sleep
// import
const sleep = require('js-sleep');