Skip to content

conradreuter/sleeep

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sleeep

npm

A promise-based function for halting the execution of the current promise-chain or async/await-block in a non-blocking way.

The implementation is written in TypeScript and therefore comes with typings already bundled.

Installation

Install the library via your favourite package manager.

npm install sleeep --save

or

yarn add sleeep

Usage

The following code should output something like Sleep: 101.337ms after 100 milliseconds.

import sleep from 'sleeep'

run()

async function run() {
  console.time('sleep')
  await sleep(100)
  console.timeEnd('sleep')
}

You can also use sleep in Promise-chains. The following code should print Hello, world! after 100 milliseconds.

import sleep from 'sleeep'

Promise.resolve('Hello, world!')
.then(sleep(100))
.then(x => console.log(x))

About

A promise-based sleep function

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published