@andytan07/delay-es

Simple delay based on ES6/ES7 Promise and async/await

Usage no npm install needed!

<script type="module">
  import andytan07DelayEs from 'https://cdn.skypack.dev/@andytan07/delay-es';
</script>

README

delay-es

A simple stupid delay function based on ES6/ES7 Promise or async/await that tends to replace setTimeout without any extra functions.

To install,

> npm install --save @andytan07/delay-es

Usage:

const delay = require("@andytan07/delay-es");

// With ES6 Promise
console.log("Before delay");
delay(1000).then(() => console.log("Delayed 1000ms"));

// With ES7 async/await
(async () => {
  console.log("Before delay");
  await delay(1000);
  console.log("Delayed 1000ms");
})();

API

As simple as:

delay(milliseconds)

Create a promise that resolves after specified milliseconds

License

MIT © Andy Tan