Make sure timeout handle is cleared
This commit is contained in:
parent
fde5b426e4
commit
32313c1df9
|
@ -1863,15 +1863,21 @@ DataSource.prototype.ready = function (obj, args) {
|
||||||
var method = args.callee;
|
var method = args.callee;
|
||||||
// Set up a callback after the connection is established to continue the method call
|
// Set up a callback after the connection is established to continue the method call
|
||||||
|
|
||||||
var onConnected = null, onError = null;
|
var onConnected = null, onError = null, timeoutHandle = null;
|
||||||
onConnected = function () {
|
onConnected = function () {
|
||||||
// Remove the error handler
|
// Remove the error handler
|
||||||
self.removeListener('error', onError);
|
self.removeListener('error', onError);
|
||||||
|
if (timeoutHandle) {
|
||||||
|
clearTimeout(timeoutHandle);
|
||||||
|
}
|
||||||
method.apply(obj, [].slice.call(args));
|
method.apply(obj, [].slice.call(args));
|
||||||
};
|
};
|
||||||
onError = function (err) {
|
onError = function (err) {
|
||||||
// Remove the connected listener
|
// Remove the connected listener
|
||||||
self.removeListener('connected', onConnected);
|
self.removeListener('connected', onConnected);
|
||||||
|
if (timeoutHandle) {
|
||||||
|
clearTimeout(timeoutHandle);
|
||||||
|
}
|
||||||
var params = [].slice.call(args);
|
var params = [].slice.call(args);
|
||||||
var cb = params.pop();
|
var cb = params.pop();
|
||||||
if (typeof cb === 'function') {
|
if (typeof cb === 'function') {
|
||||||
|
@ -1883,7 +1889,7 @@ DataSource.prototype.ready = function (obj, args) {
|
||||||
|
|
||||||
// Set up a timeout to cancel the invocation
|
// Set up a timeout to cancel the invocation
|
||||||
var timeout = this.settings.connectionTimeout || 5000;
|
var timeout = this.settings.connectionTimeout || 5000;
|
||||||
setTimeout(function() {
|
timeoutHandle = setTimeout(function () {
|
||||||
self.removeListener('error', onError);
|
self.removeListener('error', onError);
|
||||||
self.removeListener('connected', onConnected);
|
self.removeListener('connected', onConnected);
|
||||||
var params = [].slice.call(args);
|
var params = [].slice.call(args);
|
||||||
|
|
Loading…
Reference in New Issue