use try and wait routine
This commit is contained in:
parent
38a8172431
commit
721a199e7d
1 changed files with 25 additions and 10 deletions
|
|
@ -954,20 +954,35 @@ const sendPayment = async (to, amount, memo) => {
|
||||||
// eslint-disable-next-line init-declarations
|
// eslint-disable-next-line init-declarations
|
||||||
let timeoutID
|
let timeoutID
|
||||||
|
|
||||||
const invoice = await Promise.race([
|
const onMethod = new Promise(res => {
|
||||||
new Promise(res => {
|
require('../Mediator')
|
||||||
require('../Mediator')
|
.getGun()
|
||||||
.getGun()
|
.user(to)
|
||||||
|
.get(Key.ORDER_TO_RESPONSE)
|
||||||
|
.get(orderID)
|
||||||
|
.on(inv => {
|
||||||
|
if (typeof inv === 'string') {
|
||||||
|
res(inv)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const freshGunMethod = Utils.tryAndWait(
|
||||||
|
gun =>
|
||||||
|
gun
|
||||||
.user(to)
|
.user(to)
|
||||||
.get(Key.ORDER_TO_RESPONSE)
|
.get(Key.ORDER_TO_RESPONSE)
|
||||||
.get(orderID)
|
.get(orderID)
|
||||||
.on(inv => {
|
.then(),
|
||||||
if (typeof inv === 'string') {
|
v => typeof v === 'undefined'
|
||||||
clearTimeout(timeoutID)
|
)
|
||||||
res(inv)
|
|
||||||
}
|
const invoice = await Promise.race([
|
||||||
})
|
Promise.race([onMethod, freshGunMethod]).then(v => {
|
||||||
|
clearTimeout(timeoutID)
|
||||||
|
return v
|
||||||
}),
|
}),
|
||||||
|
|
||||||
new Promise((_, rej) => {
|
new Promise((_, rej) => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
rej(new Error(ErrorCode.ORDER_NOT_ANSWERED_IN_TIME))
|
rej(new Error(ErrorCode.ORDER_NOT_ANSWERED_IN_TIME))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue