@knicola/delay
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

@knicola/delay

Delay code execution for a specified amount of milliseconds. This is an isomorphic variation of require('timers/promises').setTimeout(1000).

Install

Using npm:

$ npm install @knicola/delay

Using yarn:

$ yarn add @knicola/delay

Usage

import { delay, AbortError } from '@knicola/delay'

const ac = new AbortController()

// abort after 3 seconds
setTimeout(() => ac.abort(), 3000)

try {
    await delay(10e3, ac.signal)
    // work, work ..
} catch (err) {
    if (err instanceof AbortError) {
        // operation aborted ..
    }
}

License

This project is open-sourced software licensed under the MIT license.

Readme

Keywords

Package Sidebar

Install

npm i @knicola/delay

Weekly Downloads

0

Version

0.1.1

License

MIT

Unpacked Size

7.7 kB

Total Files

9

Last publish

Collaborators

  • knicola