parent
7bb7ff2be0
commit
b456b7994e
11
index.js
11
index.js
|
@ -1,4 +1,5 @@
|
|||
'use strict';
|
||||
const pFinally = require('p-finally');
|
||||
|
||||
class TimeoutError extends Error {
|
||||
constructor(message) {
|
||||
|
@ -24,14 +25,10 @@ module.exports = (promise, ms, fallback) => new Promise((resolve, reject) => {
|
|||
reject(err);
|
||||
}, ms);
|
||||
|
||||
promise.then(
|
||||
val => {
|
||||
pFinally(
|
||||
promise.then(resolve, reject),
|
||||
() => {
|
||||
clearTimeout(timer);
|
||||
resolve(val);
|
||||
},
|
||||
err => {
|
||||
clearTimeout(timer);
|
||||
reject(err);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -31,6 +31,9 @@
|
|||
"cancel",
|
||||
"bluebird"
|
||||
],
|
||||
"dependencies": {
|
||||
"p-finally": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"delay": "^1.3.1",
|
||||
|
|
Loading…
Reference in New Issue