Skip to content

Commit

Permalink
Re-ordered when we clear private non-timeout based state.
Browse files Browse the repository at this point in the history
- This way we can successfully reject connection deferrals.

#2189
  • Loading branch information
NTaylorMullen committed Aug 16, 2013
1 parent 5869a8f commit f528b68
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/Microsoft.AspNet.SignalR.Client.JS/jquery.signalR.core.js
Expand Up @@ -860,30 +860,35 @@
/// <param name="async" type="Boolean">Whether or not to asynchronously abort the connection</param>
/// <param name="notifyServer" type="Boolean">Whether we want to notify the server that we are aborting the connection</param>
/// <returns type="signalR" />
var connection = this;
var connection = this,
// Save deferral because this is always cleaned up
deferral = connection._deferral;

// Verify that we've bound a load event.
if (connection._.deferredStartHandler) {
// Unbind the event.
_pageWindow.unbind("load", connection._.deferredStartHandler);
}

// Always clean up private non-timeout based state.
delete connection._deferral;
delete connection._.config;
delete connection._.deferredStartHandler;

// This needs to be checked despite the connection state because a connection start can be deferred until page load.
// If we've deferred the start due to a page load we need to unbind the "onLoad" -> start event.
if (!_pageLoaded && (!connection._.config || connection._.config.waitForPageLoad === true)) {
connection.log("Stopping connection prior to negotiate.");

// Reject any promises for the current connections deferred.
connection._deferral.reject(signalR._.error(resources.stoppedWhileLoading));
// If we have a deferral we should reject it
if (deferral) {
deferral.reject(signalR._.error(resources.stoppedWhileLoading));
}

// Short-circuit because the start has not been fully started.
return;
}

// Always clean up the private non-timeout based state.
delete connection._deferral;
delete connection._.config;
delete connection._.deferredStartHandler;

if (connection.state === signalR.connectionState.disconnected) {
return;
}
Expand Down

0 comments on commit f528b68

Please sign in to comment.