Simplify the code by using `p-finally`

Closes #1
This commit is contained in:
Sindre Sorhus 2017-07-02 03:41:51 +02:00
parent 7bb7ff2be0
commit b456b7994e
2 changed files with 7 additions and 7 deletions

View File

@ -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);
}
);
});

View File

@ -31,6 +31,9 @@
"cancel",
"bluebird"
],
"dependencies": {
"p-finally": "^1.0.0"
},
"devDependencies": {
"ava": "*",
"delay": "^1.3.1",