1.0.2 • Published 5 years ago

@manuelsch/sleep v1.0.2

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

@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;