This commit is contained in:
parent
339b0ac5db
commit
3a7b0ebc43
8
index.js
8
index.js
|
@ -1,5 +1,5 @@
|
||||||
'use strict';
|
"use strict";
|
||||||
const pFinally = require('p-finally');
|
const pFinally = require("p-finally");
|
||||||
|
|
||||||
class TimeoutError extends Error {
|
class TimeoutError extends Error {
|
||||||
constructor(message) {
|
constructor(message) {
|
||||||
|
@ -22,6 +22,10 @@ module.exports = (promise, ms, fallback) => new Promise((resolve, reject) => {
|
||||||
const message = typeof fallback === 'string' ? fallback : `Promise timed out after ${ms} milliseconds`;
|
const message = typeof fallback === 'string' ? fallback : `Promise timed out after ${ms} milliseconds`;
|
||||||
const err = fallback instanceof Error ? fallback : new TimeoutError(message);
|
const err = fallback instanceof Error ? fallback : new TimeoutError(message);
|
||||||
|
|
||||||
|
if (typeof promise.cancel === 'function') {
|
||||||
|
promise.cancel(err);
|
||||||
|
}
|
||||||
|
|
||||||
reject(err);
|
reject(err);
|
||||||
}, ms);
|
}, ms);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue