0.1.1 • Published 9 months ago

@knicola/delay v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

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