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 const lastRequestIDSentToUser = maybeLastRequestIDSentToUser
console.log('sendHR() -> before alreadyContactedOnCurrHandshakeNode') console.log('sendHR() -> before alreadyContactedOnCurrHandshakeNode')
/** @type {boolean} */
const alreadyContactedOnCurrHandshakeNode = await Utils.tryAndWait( const hrInHandshakeNode = await Utils.tryAndWait(
gun => gun =>
new Promise(res => { new Promise(res => {
gun gun
@ -527,11 +527,16 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => {
.get(currentHandshakeAddress) .get(currentHandshakeAddress)
.get(lastRequestIDSentToUser) .get(lastRequestIDSentToUser)
.once(data => { .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) { if (alreadyContactedOnCurrHandshakeNode) {
throw new Error(ErrorCode.ALREADY_REQUESTED_HANDSHAKE) throw new Error(ErrorCode.ALREADY_REQUESTED_HANDSHAKE)
} }