Use specialThen() for fetching epub
This commit is contained in:
parent
54af46c25a
commit
a1320fa14c
1 changed files with 6 additions and 25 deletions
|
|
@ -162,32 +162,13 @@ const tryAndWait = async (promGen, shouldRetry = () => false) => {
|
||||||
*/
|
*/
|
||||||
const pubToEpub = async pub => {
|
const pubToEpub = async pub => {
|
||||||
try {
|
try {
|
||||||
const TIMEOUT_PTR = {}
|
const epub = await require('../../Mediator/index')
|
||||||
|
|
||||||
const epubOrTimeout = await Promise.race([
|
|
||||||
CommonUtils.makePromise(res => {
|
|
||||||
require('../../Mediator/index')
|
|
||||||
.getGun()
|
.getGun()
|
||||||
.user(pub)
|
.user(pub)
|
||||||
.get('epub')
|
.get('epub')
|
||||||
.on(data => {
|
.specialThen()
|
||||||
if (typeof data === 'string') {
|
|
||||||
res(data)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
CommonUtils.makePromise(res => {
|
|
||||||
setTimeout(() => {
|
|
||||||
res(TIMEOUT_PTR)
|
|
||||||
}, 10000)
|
|
||||||
})
|
|
||||||
])
|
|
||||||
|
|
||||||
if (epubOrTimeout === TIMEOUT_PTR) {
|
return /** @type {string} */ (epub)
|
||||||
throw new Error(`Timeout inside pubToEpub()`)
|
|
||||||
}
|
|
||||||
|
|
||||||
return epubOrTimeout
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(
|
logger.error(
|
||||||
`Error inside pubToEpub for pub ${pub.slice(0, 8)}...${pub.slice(-8)}:`
|
`Error inside pubToEpub for pub ${pub.slice(0, 8)}...${pub.slice(-8)}:`
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue