From 557dbb019a7d03302d57b71c638d9c45816fb23f Mon Sep 17 00:00:00 2001 From: Federico Brigante Date: Mon, 1 Aug 2022 16:21:43 +0700 Subject: [PATCH] Timeout without error --- index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index ebd6c2d..7b3d79d 100644 --- a/index.js +++ b/index.js @@ -77,12 +77,16 @@ export default function pTimeout(promise, options) { return; } - const errorMessage = typeof message === 'string' ? message : `Promise timed out after ${milliseconds} milliseconds`; - const timeoutError = message instanceof Error ? message : new TimeoutError(errorMessage); - if (typeof promise.cancel === 'function') { promise.cancel(); } + + if (message === false) { + resolve(); + } + + const errorMessage = typeof message === 'string' ? message : `Promise timed out after ${milliseconds} milliseconds`; + const timeoutError = message instanceof Error ? message : new TimeoutError(errorMessage); reject(timeoutError); }, milliseconds);