IAServiceStub.prototype.decorateWithTimeout = function(callback) { return _bind(this, function(e) { if (e.error) { // log error message if it has any Ti.API.error(e.error); } if (!this.isTimeout()) { clearTimeout(this._timeoutid); callback(e); } }); }
IAServiceStub.prototype.send = function(request, url, action, params, httpHeadParams) { request.timeout = IAService.settings.timeout; this._onload = request.onload; this._onerror = request.onerror; request.onload = this.decorateWithTimeout(this._onload); request.onerror = this.decorateWithTimeout(this._onerror); Ti.API.info('[IAService send] Send request with url:' + url); request.open(action, url); if (httpHeadParams) { for (var headerParam in httpHeadParams) { request.setRequestHeader(headerParam, httpHeadParams[headerParam]); } } params ? request.send(params) : request.send(); this._timeoutid = setTimeout(_bind(this, function(){ this._timeout_status = IAService.consts.TIMEOUT_TRIGGERED; this._onerror({ error:'[IAService timeout callback] Request time out.' }); }), IAService.settings.timeoutCheck); }