promise-timeout-wrapper

1.0.0 • Public • Published

#Promise Timeout Wrapper Simple timeout wrapper for your asynchronous functions ##Installation

$ npm install promise-timeout-wrapper

##Usage

timeoutPromiseWrapper(promise, timeout, customErrorInstance)

Rejects a promise with a TimeoutPromiseError or custom error. Parameters:

  • promise: Promise - Promise function.
  • timeout: number - Number of milliseconds to reject promise.
  • customErrorInstance - Custom error instance.

TimeoutPromiseError

Special error class with error message - 'Timeout promise error'.

Examples

const timeoutPromiseWrapper = require('promise-timeout-wrapper');

const asyncFunction = makeSmth();
const TIMEOUT = 1000;
const asyncFunctionTimeout = timeoutPromiseWrapper(asyncFunction, TIMEOUT);

(async () => {
    await asyncFunctionTimeout();
})();

Readme

Keywords

Package Sidebar

Install

npm i promise-timeout-wrapper

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

4.75 kB

Total Files

5

Last publish

Collaborators

  • kayrosik