npm.io
0.1.1 • Published 2 years ago

@knicola/delay

Licence
MIT
Version
0.1.1
Deps
0
Size
8 kB
Vulns
0
Weekly
0

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

Keywords