1.0.0 • Published 5 years ago

promise-timeout-wrapper v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

#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();
})();