promisify is broken

This commit is contained in:
Daniel Lugo 2020-01-28 17:49:41 -04:00
parent 438b6f1383
commit a43ff12cc5

View file

@ -9,7 +9,7 @@ const ErrorCode = require('./errorCode')
const Getters = require('./getters') const Getters = require('./getters')
const Key = require('./key') const Key = require('./key')
const Utils = require('./utils') const Utils = require('./utils')
const { promisifyGunNode: p } = Utils // const { promisifyGunNode: p } = Utils
const { isHandshakeRequest } = require('./schema') const { isHandshakeRequest } = require('./schema')
/** /**
* @typedef {import('./SimpleGUN').GUNNode} GUNNode * @typedef {import('./SimpleGUN').GUNNode} GUNNode
@ -1052,7 +1052,7 @@ const saveSeedBackup = async (mnemonicPhrase, user, SEA) => {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
const disconnect = async pub => { const disconnect = async pub => {
const user = p(require('../Mediator').getUser()) const user = require('../Mediator').getUser()
if (!(await Utils.successfulHandshakeAlreadyExists(pub))) { if (!(await Utils.successfulHandshakeAlreadyExists(pub))) {
throw new Error('No handshake exists for this pub') throw new Error('No handshake exists for this pub')
} }
@ -1061,25 +1061,57 @@ const disconnect = async pub => {
pub pub
)) ))
await user await new Promise((res, rej) => {
.get(Key.USER_TO_INCOMING) user
.get(pub) .get(Key.USER_TO_INCOMING)
.put(null) .get(pub)
.put(null, ack => {
if (ack.err) {
rej(new Error(ack.err))
} else {
res()
}
})
})
await user await new Promise((res, rej) => {
.get(Key.RECIPIENT_TO_OUTGOING) user
.get(pub) .get(Key.RECIPIENT_TO_OUTGOING)
.put(null) .get(pub)
.put(null, ack => {
if (ack.err) {
rej(new Error(ack.err))
} else {
res()
}
})
})
await user await new Promise((res, rej) => {
.get(Key.USER_TO_LAST_REQUEST_SENT) user
.get(pub) .get(Key.USER_TO_LAST_REQUEST_SENT)
.put(null) .get(pub)
.put(null, ack => {
if (ack.err) {
rej(new Error(ack.err))
} else {
res()
}
})
})
await user await new Promise((res, rej) => {
.get(Key.OUTGOINGS) user
.get(outGoingID) .get(Key.OUTGOINGS)
.put(null) .get(outGoingID)
.put(null, ack => {
if (ack.err) {
rej(new Error(ack.err))
} else {
res()
}
})
})
} }
module.exports = { module.exports = {