From 8379fa278fd4fb086c40a204435a0d359e415993 Mon Sep 17 00:00:00 2001 From: Ian Wehrman Date: Thu, 14 Mar 2013 14:34:21 -0700 Subject: [PATCH] Modify connectToURL so that the promise it returns is not resolved until the socket it creates is completely open. --- src/LiveDevelopment/Inspector/Inspector.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/LiveDevelopment/Inspector/Inspector.js b/src/LiveDevelopment/Inspector/Inspector.js index aae167a7980..37320842a4e 100644 --- a/src/LiveDevelopment/Inspector/Inspector.js +++ b/src/LiveDevelopment/Inspector/Inspector.js @@ -151,11 +151,19 @@ define(function Inspector(require, exports, module) { /** WebSocket reported an error */ function _onError(error) { + if (_connectDeferred) { + _connectDeferred.reject(); + _connectDeferred = null; + } $exports.triggerHandler("error", [error]); } /** WebSocket did open */ function _onConnect() { + if (_connectDeferred) { + _connectDeferred.resolve(); + _connectDeferred = null; + } $exports.triggerHandler("connect"); } @@ -266,15 +274,12 @@ define(function Inspector(require, exports, module) { _connectDeferred = deferred; var promise = getDebuggableWindows(); promise.done(function onGetAvailableSockets(response) { - if (deferred.isRejected()) { - return; - } var i, page; for (i in response) { page = response[i]; if (page.webSocketDebuggerUrl && page.url.indexOf(url) === 0) { connect(page.webSocketDebuggerUrl); - deferred.resolve(); + // _connectDeferred may be resolved by onConnect or rejected by onError return; } }