use on(), wait 10 seconds for epub to arrive
This commit is contained in:
parent
0f0e428391
commit
c8883b55d1
1 changed files with 9 additions and 21 deletions
|
|
@ -210,33 +210,21 @@ const tryAndWait = async (promGen, shouldRetry = () => false) => {
|
||||||
* @param {string} pub
|
* @param {string} pub
|
||||||
* @returns {Promise<string>}
|
* @returns {Promise<string>}
|
||||||
*/
|
*/
|
||||||
const pubToEpub = async pub => {
|
const pubToEpub = pub => {
|
||||||
try {
|
try {
|
||||||
const epub = await tryAndWait(async gun => {
|
return timeout10(
|
||||||
const _epub = await CommonUtils.makePromise(res => {
|
CommonUtils.makePromise(res => {
|
||||||
gun
|
require('../../Mediator/index')
|
||||||
|
.getGun()
|
||||||
.user(pub)
|
.user(pub)
|
||||||
.get('epub')
|
.get('epub')
|
||||||
.once(
|
.on(data => {
|
||||||
data => {
|
if (typeof data === 'string') {
|
||||||
res(data)
|
res(data)
|
||||||
},
|
|
||||||
{
|
|
||||||
wait: 1000
|
|
||||||
}
|
}
|
||||||
)
|
})
|
||||||
})
|
})
|
||||||
|
)
|
||||||
if (typeof _epub !== 'string') {
|
|
||||||
throw new TypeError(
|
|
||||||
`Expected gun.user(pub).get(epub) to be an string. Instead got: ${typeof _epub}`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return _epub
|
|
||||||
})
|
|
||||||
|
|
||||||
return epub
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(err)
|
logger.error(err)
|
||||||
throw new Error(`pubToEpub() -> ${err.message}`)
|
throw new Error(`pubToEpub() -> ${err.message}`)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue