From f2345b7d1c035422dad553a4541ee486d952afa9 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 28 Jun 2020 14:39:43 -0400 Subject: Use deferPromise (#630) * Use deferPromise * Move definition * Implement promiseTimeout using deferPromise --- ext/fg/js/popup.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'ext/fg/js') diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index 5ee62c9b..931813de 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -229,12 +229,11 @@ class Popup { return new Promise((resolve, reject) => { const tokenMap = new Map(); let timer = null; - let frameLoadedResolve = null; - let frameLoadedReject = null; - const frameLoaded = new Promise((resolve2, reject2) => { - frameLoadedResolve = resolve2; - frameLoadedReject = reject2; - }); + let { + promise: frameLoadedPromise, + resolve: frameLoadedResolve, + reject: frameLoadedReject + } = deferPromise(); const postMessage = (action, params) => { const contentWindow = frame.contentWindow; @@ -261,7 +260,7 @@ class Popup { if (!isObject(message)) { return; } const {action, params} = message; if (!isObject(params)) { return; } - await frameLoaded; + await frameLoadedPromise; if (timer === null) { return; } // Done switch (action) { @@ -331,7 +330,7 @@ class Popup { frame.addEventListener('load', onLoad); // Prevent unhandled rejections - frameLoaded.catch(() => {}); // NOP + frameLoadedPromise.catch(() => {}); // NOP setupFrame(frame); }); -- cgit v1.2.3