clear timeout
This commit is contained in:
parent
e2c1c8fa0b
commit
dd3b16832b
1 changed files with 17 additions and 4 deletions
|
|
@ -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)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue