From c2050c30fbf56f098460fe829779665b3f5a19ff Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Tue, 17 Nov 2020 15:30:13 -0400 Subject: [PATCH] use once --- services/gunDB/contact-api/utils/index.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/services/gunDB/contact-api/utils/index.js b/services/gunDB/contact-api/utils/index.js index 49b5886c..bcab3105 100644 --- a/services/gunDB/contact-api/utils/index.js +++ b/services/gunDB/contact-api/utils/index.js @@ -3,7 +3,7 @@ */ /* eslint-disable init-declarations */ const logger = require('winston') -const { Constants } = require('shock-common') +const { Constants, Utils: CommonUtils } = require('shock-common') const Key = require('../key') @@ -213,10 +213,19 @@ const tryAndWait = async (promGen, shouldRetry = () => false) => { const pubToEpub = async pub => { try { const epub = await tryAndWait(async gun => { - const _epub = await gun - .user(pub) - .get('epub') - .then() + const _epub = await CommonUtils.makePromise(res => { + gun + .user(pub) + .get('epub') + .once( + data => { + res(data) + }, + { + wait: 1000 + } + ) + }) if (typeof _epub !== 'string') { throw new TypeError(