From a1320fa14c1048d01beea3f966fbd662e2f373e0 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Wed, 20 Oct 2021 12:14:59 -0400 Subject: [PATCH] Use specialThen() for fetching epub --- services/gunDB/contact-api/utils/index.js | 31 +++++------------------ 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/services/gunDB/contact-api/utils/index.js b/services/gunDB/contact-api/utils/index.js index 23090361..60a744cc 100644 --- a/services/gunDB/contact-api/utils/index.js +++ b/services/gunDB/contact-api/utils/index.js @@ -162,32 +162,13 @@ const tryAndWait = async (promGen, shouldRetry = () => false) => { */ const pubToEpub = async pub => { try { - const TIMEOUT_PTR = {} + const epub = await require('../../Mediator/index') + .getGun() + .user(pub) + .get('epub') + .specialThen() - const epubOrTimeout = await Promise.race([ - CommonUtils.makePromise(res => { - require('../../Mediator/index') - .getGun() - .user(pub) - .get('epub') - .on(data => { - if (typeof data === 'string') { - res(data) - } - }) - }), - CommonUtils.makePromise(res => { - setTimeout(() => { - res(TIMEOUT_PTR) - }, 10000) - }) - ]) - - if (epubOrTimeout === TIMEOUT_PTR) { - throw new Error(`Timeout inside pubToEpub()`) - } - - return epubOrTimeout + return /** @type {string} */ (epub) } catch (err) { logger.error( `Error inside pubToEpub for pub ${pub.slice(0, 8)}...${pub.slice(-8)}:`