No nested tryAndWait
This commit is contained in:
parent
4212ea4612
commit
19f14e6d83
1 changed files with 92 additions and 87 deletions
|
|
@ -1,6 +1,8 @@
|
|||
/**
|
||||
* @format
|
||||
*/
|
||||
const logger = require('winston')
|
||||
|
||||
const ErrorCode = require('../errorCode')
|
||||
const Key = require('../key')
|
||||
const Schema = require('../schema')
|
||||
|
|
@ -12,6 +14,8 @@ const Utils = require('../utils')
|
|||
* @typedef {import('../SimpleGUN').UserGUNNode} UserGUNNode
|
||||
*/
|
||||
|
||||
let procid = 0
|
||||
|
||||
/**
|
||||
* @throws {Error} NOT_AUTH
|
||||
* @param {UserGUNNode} user
|
||||
|
|
@ -23,17 +27,16 @@ const onAcceptedRequests = (user, SEA) => {
|
|||
throw new Error(ErrorCode.NOT_AUTH)
|
||||
}
|
||||
|
||||
const mySecret = require('../../Mediator').getMySecret()
|
||||
|
||||
if (typeof mySecret !== 'string') {
|
||||
console.log("Jobs.onAcceptedRequests() -> typeof mySecret !== 'string'")
|
||||
return
|
||||
}
|
||||
procid++
|
||||
|
||||
user
|
||||
.get(Key.STORED_REQS)
|
||||
.map()
|
||||
.once(async (storedReq, id) => {
|
||||
logger.info(
|
||||
`------------------------------------\nPROCID:${procid}\n---------------------------------------`
|
||||
)
|
||||
const mySecret = require('../../Mediator').getMySecret()
|
||||
try {
|
||||
if (!Schema.isStoredRequest(storedReq)) {
|
||||
throw new TypeError(
|
||||
|
|
@ -70,16 +73,13 @@ const onAcceptedRequests = (user, SEA) => {
|
|||
return
|
||||
}
|
||||
|
||||
const gun = require('../../Mediator').getGun()
|
||||
const user = require('../../Mediator').getUser()
|
||||
|
||||
const recipientEpub = await Utils.pubToEpub(recipientPub)
|
||||
const ourSecret = await SEA.secret(recipientEpub, user._.sea)
|
||||
|
||||
if (typeof ourSecret !== 'string') {
|
||||
throw new TypeError("typeof ourSecret !== 'string'")
|
||||
}
|
||||
|
||||
await Utils.tryAndWait(
|
||||
(gun, user) =>
|
||||
new Promise((res, rej) => {
|
||||
await new Promise((res, rej) => {
|
||||
gun
|
||||
.get(Key.HANDSHAKE_NODES)
|
||||
.get(requestAddress)
|
||||
|
|
@ -104,6 +104,12 @@ const onAcceptedRequests = (user, SEA) => {
|
|||
throw new TypeError("typeof feedID !== 'string'")
|
||||
}
|
||||
|
||||
logger.info(`onAcceptedRequests -> decrypted feed ID: ${feedID}`)
|
||||
|
||||
logger.info(
|
||||
'Will now try to access the other users outgoing feed'
|
||||
)
|
||||
|
||||
const maybeFeedOnRecipientsOutgoings = await Utils.tryAndWait(
|
||||
gun =>
|
||||
new Promise(res => {
|
||||
|
|
@ -162,7 +168,6 @@ const onAcceptedRequests = (user, SEA) => {
|
|||
res()
|
||||
})
|
||||
})
|
||||
)
|
||||
} catch (err) {
|
||||
console.warn(`Jobs.onAcceptedRequests() -> ${err.message}`)
|
||||
console.log(err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue