From dd3b16832bc79ffcb7b0e301d93733c6c2282369 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Thu, 27 Feb 2020 13:46:50 -0400 Subject: [PATCH] clear timeout --- services/gunDB/contact-api/utils/index.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/services/gunDB/contact-api/utils/index.js b/services/gunDB/contact-api/utils/index.js index 4a97b0d9..c34a143b 100644 --- a/services/gunDB/contact-api/utils/index.js +++ b/services/gunDB/contact-api/utils/index.js @@ -1,3 +1,4 @@ +/* eslint-disable init-declarations */ /** * @format */ @@ -29,10 +30,16 @@ const mySecret = () => Promise.resolve(require('../../Mediator').getMySecret()) * @returns {Promise} */ const timeout10 = promise => { + /** @type {NodeJS.Timeout} */ + // @ts-ignore + let timeoutID return Promise.race([ - promise, + promise.then(() => { + clearTimeout(timeoutID) + }), + new Promise((_, rej) => { - setTimeout(() => { + timeoutID = setTimeout(() => { rej(new Error(ErrorCode.TIMEOUT_ERR)) }, 10000) }) @@ -45,10 +52,16 @@ const timeout10 = promise => { * @returns {Promise} */ const timeout5 = promise => { + /** @type {NodeJS.Timeout} */ + // @ts-ignore + let timeoutID return Promise.race([ - promise, + promise.then(() => { + clearTimeout(timeoutID) + }), + new Promise((_, rej) => { - setTimeout(() => { + timeoutID = setTimeout(() => { rej(new Error(ErrorCode.TIMEOUT_ERR)) }, 5000) })