Promise based sleep function for Node and browser.
$ npm install promisleep
The library is available over a CDN:
<script src="https://unpkg.com/promisleep@latest/dist/promisleep.umd.js"></script>
<!-- Or the minified version -->
<script src="https://unpkg.com/promisleep@latest/dist/promisleep.umd.min.js"></script>
const promisleep = require("promisleep");
promisleep(3000)
.then(() => console.log("⏰ Delayed for 3 seconds..."));
If you perfer to use the ES2016 async/await
syntax:
import promisleep from "promisleep";
const letMeSleep = async () => {
console.log("😴 I'm gonna sleep for 3 seconds...");
await promisleep(5000);
console.log("⏰ I woke up after 5 seconds...");
}
letMeSleep();