@whi/promise-timeout
v0.2.2
Published
A micro-package for scheduling a timeout rejection on a Promise
Downloads
25
Readme
new PromiseTimeout( executor, timeout )
This micro-package is intended to help with scheduling timeout rejection on a Promise.
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