@manuelsch/sleep
v1.0.2
Published
A simple, Promise-based sleep function for TypeScript applications
Downloads
2
Readme
@manuelsch/sleep 😴
A simple, Promise-based sleep function for TypeScript applications.
- Works with
async/await
- Usable in the browser and with node.js
Installation ⬇
npm install @manuelsch/sleep --save
yarn add @manuelsch/sleep
Usage:
import sleep from '@manuelsch/sleep';
async someFunction() {
console.log('Print this immediately');
await sleep(1000);
console.log('Print this 1 second later');
}
This is the whole source code:
const sleep = async (duration: number) => new Promise<void>(resolve => setTimeout(() => resolve(), duration));
export default sleep;