From 2c512ae2d4cd73dfcbb71bb49a22a9bea0d90e7c Mon Sep 17 00:00:00 2001 From: Daniel Brain Date: Thu, 21 Jul 2016 19:42:15 -0700 Subject: [PATCH] Add default timeout to onWindowReady --- src/lib/ready.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/ready.js b/src/lib/ready.js index de48c30f..df28df52 100644 --- a/src/lib/ready.js +++ b/src/lib/ready.js @@ -29,8 +29,9 @@ export function initOnReady() { } } -export function onWindowReady(win) { - return new promise.Promise(resolve => { +export function onWindowReady(win, timeout = 5000) { + return new promise.Promise((resolve, reject) => { + if (readyWindows.indexOf(win) !== -1) { return resolve(win); } else { @@ -38,6 +39,8 @@ export function onWindowReady(win) { win, resolve }); + + setTimeout(() => reject(new Error(`Bridge did not load after ${timeout}ms`)), timeout); } }); } \ No newline at end of file