timeout2 routine
This commit is contained in:
parent
724350ebd7
commit
465a5049c2
1 changed files with 24 additions and 0 deletions
|
|
@ -70,6 +70,29 @@ const timeout5 = promise => {
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @template T
|
||||||
|
* @param {Promise<T>} promise
|
||||||
|
* @returns {Promise<T>}
|
||||||
|
*/
|
||||||
|
const timeout2 = promise => {
|
||||||
|
/** @type {NodeJS.Timeout} */
|
||||||
|
// @ts-ignore
|
||||||
|
let timeoutID
|
||||||
|
return Promise.race([
|
||||||
|
promise.then(v => {
|
||||||
|
clearTimeout(timeoutID)
|
||||||
|
return v
|
||||||
|
}),
|
||||||
|
|
||||||
|
new Promise((_, rej) => {
|
||||||
|
timeoutID = setTimeout(() => {
|
||||||
|
rej(new Error(Constants.ErrorCode.TIMEOUT_ERR))
|
||||||
|
}, 2000)
|
||||||
|
})
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @template T
|
* @template T
|
||||||
* @param {(gun: GUNNode, user: UserGUNNode) => Promise<T>} promGen The function
|
* @param {(gun: GUNNode, user: UserGUNNode) => Promise<T>} promGen The function
|
||||||
|
|
@ -330,5 +353,6 @@ module.exports = {
|
||||||
mySecret,
|
mySecret,
|
||||||
promisifyGunNode: require('./promisifygun'),
|
promisifyGunNode: require('./promisifygun'),
|
||||||
timeout5,
|
timeout5,
|
||||||
|
timeout2,
|
||||||
isNodeOnline
|
isNodeOnline
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue