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'; 'use strict';
const pFinally = require('p-finally');
class TimeoutError extends Error { class TimeoutError extends Error {
constructor(message) { constructor(message) {
@ -24,14 +25,10 @@ module.exports = (promise, ms, fallback) => new Promise((resolve, reject) => {
reject(err); reject(err);
}, ms); }, ms);
promise.then( pFinally(
val => { promise.then(resolve, reject),
() => {
clearTimeout(timer); clearTimeout(timer);
resolve(val);
},
err => {
clearTimeout(timer);
reject(err);
} }
); );
}); });

View File

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