clear timeout

This commit is contained in:
Daniel Lugo 2020-02-27 13:46:50 -04:00
parent e2c1c8fa0b
commit dd3b16832b

View file

@ -1,3 +1,4 @@
/* eslint-disable init-declarations */
/** /**
* @format * @format
*/ */
@ -29,10 +30,16 @@ const mySecret = () => Promise.resolve(require('../../Mediator').getMySecret())
* @returns {Promise<T>} * @returns {Promise<T>}
*/ */
const timeout10 = promise => { const timeout10 = promise => {
/** @type {NodeJS.Timeout} */
// @ts-ignore
let timeoutID
return Promise.race([ return Promise.race([
promise, promise.then(() => {
clearTimeout(timeoutID)
}),
new Promise((_, rej) => { new Promise((_, rej) => {
setTimeout(() => { timeoutID = setTimeout(() => {
rej(new Error(ErrorCode.TIMEOUT_ERR)) rej(new Error(ErrorCode.TIMEOUT_ERR))
}, 10000) }, 10000)
}) })
@ -45,10 +52,16 @@ const timeout10 = promise => {
* @returns {Promise<T>} * @returns {Promise<T>}
*/ */
const timeout5 = promise => { const timeout5 = promise => {
/** @type {NodeJS.Timeout} */
// @ts-ignore
let timeoutID
return Promise.race([ return Promise.race([
promise, promise.then(() => {
clearTimeout(timeoutID)
}),
new Promise((_, rej) => { new Promise((_, rej) => {
setTimeout(() => { timeoutID = setTimeout(() => {
rej(new Error(ErrorCode.TIMEOUT_ERR)) rej(new Error(ErrorCode.TIMEOUT_ERR))
}, 5000) }, 5000)
}) })