run disconnect-related writes in parallel

This commit is contained in:
Daniel Lugo 2020-07-24 12:15:07 -04:00
parent 18844d2c55
commit cd9c7983c8

View file

@ -372,7 +372,10 @@ const cleanup = async pub => {
const outGoingID = await Utils.recipientToOutgoingID(pub) const outGoingID = await Utils.recipientToOutgoingID(pub)
await new Promise((res, rej) => { const promises = []
promises.push(
new Promise((res, rej) => {
user user
.get(Key.USER_TO_INCOMING) .get(Key.USER_TO_INCOMING)
.get(pub) .get(pub)
@ -384,8 +387,10 @@ const cleanup = async pub => {
} }
}) })
}) })
)
await new Promise((res, rej) => { promises.push(
new Promise((res, rej) => {
user user
.get(Key.RECIPIENT_TO_OUTGOING) .get(Key.RECIPIENT_TO_OUTGOING)
.get(pub) .get(pub)
@ -397,8 +402,10 @@ const cleanup = async pub => {
} }
}) })
}) })
)
await new Promise((res, rej) => { promises.push(
new Promise((res, rej) => {
user user
.get(Key.USER_TO_LAST_REQUEST_SENT) .get(Key.USER_TO_LAST_REQUEST_SENT)
.get(pub) .get(pub)
@ -410,9 +417,11 @@ const cleanup = async pub => {
} }
}) })
}) })
)
if (outGoingID) { if (outGoingID) {
await new Promise((res, rej) => { promises.push(
new Promise((res, rej) => {
user user
.get(Key.OUTGOINGS) .get(Key.OUTGOINGS)
.get(outGoingID) .get(outGoingID)
@ -424,7 +433,10 @@ const cleanup = async pub => {
} }
}) })
}) })
)
} }
await Promise.all(promises)
} }
/** /**
@ -1227,9 +1239,7 @@ const disconnect = async pub => {
throw new Error('No handshake exists for this pub') throw new Error('No handshake exists for this pub')
} }
await cleanup(pub) await Promise.all([cleanup(pub), generateHandshakeAddress()])
await generateHandshakeAddress()
} }
/** /**