retry on undefined

This commit is contained in:
Daniel Lugo 2020-02-24 18:40:42 -04:00
parent 0488e322b6
commit 466f12de16

View file

@ -518,8 +518,8 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => {
const lastRequestIDSentToUser = maybeLastRequestIDSentToUser
console.log('sendHR() -> before alreadyContactedOnCurrHandshakeNode')
/** @type {boolean} */
const alreadyContactedOnCurrHandshakeNode = await Utils.tryAndWait(
const hrInHandshakeNode = await Utils.tryAndWait(
gun =>
new Promise(res => {
gun
@ -527,11 +527,16 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => {
.get(currentHandshakeAddress)
.get(lastRequestIDSentToUser)
.once(data => {
res(typeof data !== 'undefined')
})
res(data)
})
}),
// force retry on undefined in case the undefined was a false negative
v => typeof v === 'undefined'
)
const alreadyContactedOnCurrHandshakeNode =
typeof hrInHandshakeNode !== 'undefined'
if (alreadyContactedOnCurrHandshakeNode) {
throw new Error(ErrorCode.ALREADY_REQUESTED_HANDSHAKE)
}