Skip to content

Promise based sleep function for Node and browser.

License

Notifications You must be signed in to change notification settings

risan/promisleep

Repository files navigation

Promisleep

Build Status Test Covarage Latest Version

Promise based sleep function for Node and browser.

Installation

$ npm install promisleep

CDN

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>

Usage

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();

License

MIT © Risan Bagja Pradana

About

Promise based sleep function for Node and browser.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published