From 8450727e4c7237db1c720e5c2f5fff4da7366bb6 Mon Sep 17 00:00:00 2001 From: James Gentes Date: Mon, 24 Feb 2020 11:20:25 -0800 Subject: [PATCH] Fix for hanging timeout When using methods from this library, there's a ~10 second delay before the process exits. It's due to the `setTimeout` here, which never gets cleared if the promise resolves successfully. Adding a `clearTimeout` here takes care of that. --- src/utilities/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/utilities/index.js b/src/utilities/index.js index 1d1b891..82e00df 100644 --- a/src/utilities/index.js +++ b/src/utilities/index.js @@ -9,8 +9,11 @@ */ const promiseTimeout = (promise, ms, error = new Error("ASYNC Function Call Timed Out!!!")) => { return new Promise((resolve, reject) => { - setTimeout(() => reject(error), ms); - promise.then(resolve).catch(reject); + const timer = setTimeout(() => reject(error), ms); + promise.then(p => { + clearTimeout(timer); + resolve(p); + }).catch(reject); }); };