Skip to content

Commit

Permalink
Modify connectToURL so that the promise it returns is not resolved un…
Browse files Browse the repository at this point in the history
…til the socket it creates is completely open.
  • Loading branch information
Ian Wehrman committed Mar 14, 2013
1 parent e9fd9e0 commit 8379fa2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/LiveDevelopment/Inspector/Inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 8379fa2

Please sign in to comment.