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
|
* @format
|
||||||
*/
|
*/
|
||||||
|
const logger = require('winston')
|
||||||
|
|
||||||
const ErrorCode = require('../errorCode')
|
const ErrorCode = require('../errorCode')
|
||||||
const Key = require('../key')
|
const Key = require('../key')
|
||||||
const Schema = require('../schema')
|
const Schema = require('../schema')
|
||||||
|
|
@ -12,6 +14,8 @@ const Utils = require('../utils')
|
||||||
* @typedef {import('../SimpleGUN').UserGUNNode} UserGUNNode
|
* @typedef {import('../SimpleGUN').UserGUNNode} UserGUNNode
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
let procid = 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws {Error} NOT_AUTH
|
* @throws {Error} NOT_AUTH
|
||||||
* @param {UserGUNNode} user
|
* @param {UserGUNNode} user
|
||||||
|
|
@ -23,17 +27,16 @@ const onAcceptedRequests = (user, SEA) => {
|
||||||
throw new Error(ErrorCode.NOT_AUTH)
|
throw new Error(ErrorCode.NOT_AUTH)
|
||||||
}
|
}
|
||||||
|
|
||||||
const mySecret = require('../../Mediator').getMySecret()
|
procid++
|
||||||
|
|
||||||
if (typeof mySecret !== 'string') {
|
|
||||||
console.log("Jobs.onAcceptedRequests() -> typeof mySecret !== 'string'")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
user
|
user
|
||||||
.get(Key.STORED_REQS)
|
.get(Key.STORED_REQS)
|
||||||
.map()
|
.map()
|
||||||
.once(async (storedReq, id) => {
|
.once(async (storedReq, id) => {
|
||||||
|
logger.info(
|
||||||
|
`------------------------------------\nPROCID:${procid}\n---------------------------------------`
|
||||||
|
)
|
||||||
|
const mySecret = require('../../Mediator').getMySecret()
|
||||||
try {
|
try {
|
||||||
if (!Schema.isStoredRequest(storedReq)) {
|
if (!Schema.isStoredRequest(storedReq)) {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
|
|
@ -70,16 +73,13 @@ const onAcceptedRequests = (user, SEA) => {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const gun = require('../../Mediator').getGun()
|
||||||
|
const user = require('../../Mediator').getUser()
|
||||||
|
|
||||||
const recipientEpub = await Utils.pubToEpub(recipientPub)
|
const recipientEpub = await Utils.pubToEpub(recipientPub)
|
||||||
const ourSecret = await SEA.secret(recipientEpub, user._.sea)
|
const ourSecret = await SEA.secret(recipientEpub, user._.sea)
|
||||||
|
|
||||||
if (typeof ourSecret !== 'string') {
|
await new Promise((res, rej) => {
|
||||||
throw new TypeError("typeof ourSecret !== 'string'")
|
|
||||||
}
|
|
||||||
|
|
||||||
await Utils.tryAndWait(
|
|
||||||
(gun, user) =>
|
|
||||||
new Promise((res, rej) => {
|
|
||||||
gun
|
gun
|
||||||
.get(Key.HANDSHAKE_NODES)
|
.get(Key.HANDSHAKE_NODES)
|
||||||
.get(requestAddress)
|
.get(requestAddress)
|
||||||
|
|
@ -104,6 +104,12 @@ const onAcceptedRequests = (user, SEA) => {
|
||||||
throw new TypeError("typeof feedID !== 'string'")
|
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(
|
const maybeFeedOnRecipientsOutgoings = await Utils.tryAndWait(
|
||||||
gun =>
|
gun =>
|
||||||
new Promise(res => {
|
new Promise(res => {
|
||||||
|
|
@ -162,7 +168,6 @@ const onAcceptedRequests = (user, SEA) => {
|
||||||
res()
|
res()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
)
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn(`Jobs.onAcceptedRequests() -> ${err.message}`)
|
console.warn(`Jobs.onAcceptedRequests() -> ${err.message}`)
|
||||||
console.log(err)
|
console.log(err)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue