sleep-anywhere
v2.1.2
Published
A sleep function you can use anywhere
Downloads
182
Readme
sleep-anywhere
An isomorphic sleep function you can use anywhere. Only required in the browser or isomorphic code - if your code runs on NodeJs only use this instead:
import { setTimeout as sleep } from 'node:timers/promises'
Example
import sleep from 'sleep-anywhere'
const result = await sleep(5000, 'later')
console.log('5s', result)
// 5s later
sleep(ms, [returnValue]) ⇒ Promise ⏏
Returns a promise which fulfils after ms
milliseconds with the supplied returnValue
.
Kind: Exported function
| Param | Type | Description | | --- | --- | --- | | ms | number | How long in milliseconds to sleep for. | | [returnValue] | * | The value to return. |
Load anywhere
This library is compatible with Node.js, the Web and any style of module loader. It can be loaded anywhere, natively without transpilation.
Node.js CommonJS:
const sleep = require('sleep-anywhere')
Node.js ECMAScript Module:
import sleep from 'sleep-anywhere'
Within a modern browser ECMAScript Module:
import sleep from './node_modules/sleep-anywhere/index.js'
© 2018-24 Lloyd Brookes <[email protected]>.