0.2.2 • Published 8 months ago

@whi/promise-timeout v0.2.2

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

npm.io

new PromiseTimeout( executor, timeout )

This micro-package is intended to help with scheduling timeout rejection on a Promise.

npm.io npm.io npm.io

Overview

Install

npm i @whi/promise-timeout

Usage

const { PromiseTimeout } = require('@whi/promise-timeout');

await new PromiseTimeout( (f,r) => {
}, 1000 );
// throw TimeoutError

Optionally, attach timeout to the native Promise as a method so that you can add timeouts to existing Promises.

require('@whi/promise-timeout').bindNative();

await Promise.timeout(
    new Promise( () => null ), // Promise that will never settle
    1000,
);
// throw TimeoutError

API Reference

See docs/API.md

Contributing

See CONTRIBUTING.md