From 3a7b0ebc431c75b17a8f0a935d20fb8b9f747c85 Mon Sep 17 00:00:00 2001 From: Mikhail Silaev Date: Tue, 7 Nov 2017 18:19:52 +0300 Subject: [PATCH] Fixing sindresorhus/got#394 --- index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 9748b9b..50ca1da 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ -'use strict'; -const pFinally = require('p-finally'); +"use strict"; +const pFinally = require("p-finally"); class TimeoutError extends Error { 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 err = fallback instanceof Error ? fallback : new TimeoutError(message); + if (typeof promise.cancel === 'function') { + promise.cancel(err); + } + reject(err); }, ms);