aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-06-28 14:39:43 -0400
committerGitHub <noreply@github.com>2020-06-28 14:39:43 -0400
commitf2345b7d1c035422dad553a4541ee486d952afa9 (patch)
treea13d87b874b28b1be9cfe8e343cb37c780107883 /ext/fg/js
parent7b5dd5c310f7ec4d7f6e329367d34258cce10e8e (diff)
Use deferPromise (#630)
* Use deferPromise * Move definition * Implement promiseTimeout using deferPromise
Diffstat (limited to 'ext/fg/js')
-rw-r--r--ext/fg/js/popup.js15
1 files changed, 7 insertions, 8 deletions
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);
});