promise chain timeout rejection
Reject promise (and all following) if it takes more than a set duration
Usage
Constructor defines a timeout in milliseconds.
const PromiseChainTimeoutRejection = ; const promiseTimeout = 1000;
Method globalTimeoutRejection
wraps a promise in a promise, that acts in the exact same way as
the original promise (if the promise returns something in that time), otherwise rejects with a specific PromiseTimeOutError
error.
promiseTimeout;
Method chainTimeoutRejection
wraps one chained promise in a promise, that acts in the exact same way as
the original promise (if the global promise has not timeout), otherwise rejects with a specific PromiseAlreadyTimedOutError
error.
let hasExecutedSecondPromise = false;let errorSubPromise; promiseTimeout;
Lambda use case
This package was created in order to handle lambda timeout. Lambda provides a getRemainingTimeInMillis
method in the context
object that gives the remaining time before lambda timeout.
So calling the constructor with that function allows to anticipate lambda timeout:
const promiseTimeout = context - 500;