Skip to content

A Javascript micro-package for scheduling a timeout rejection on a Promise

Notifications You must be signed in to change notification settings

mjbrisebois/js-promise-timeout

Repository files navigation

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

About

A Javascript micro-package for scheduling a timeout rejection on a Promise

Resources

Stars

Watchers

Forks

Packages

No packages published