var params = { | this.pollingTimeout = timeout * 1000 + 20000;
>
> var self = this;
>
> if (this.pollingEnabled) return false;
> this.pollingEnabled = true;
>
> function checkTimeout () {
> if (self.pollingEnabled) {
> console.error('request failed to response, restar
> try {
> self.currentPollRequest.removeAllListeners();
> self.currentPollRequest.on('error', function
> self.currentPollRequest.abort();
> // restart polling...
> } catch (err) {
> console.error(err)
> }
> self.lastOffset = null;
> self.pollingEnabled = false;
> self.startPolling(timeout)
> }
> }
>
> clearTimeout(this.pollingTimeoutId);
> this.pollingTimeoutId = setTimeout(checkTimeout, this.pol
> this.currentPollRequest = this._poll(timeout, null, funct
> self.pollCount++;
> // console.log(err, response ? response.statusCode :
> var i;
> if (err || response.statusCode !== 200) {
> self.lastOffset = null;
> self.emit('error', err || new Error('unexpect res
> } else {
> try {
> body = JSON.parse(body)
> } catch (err) {
> self.lastOffset = null;
> self.emit('error', err);
> }
> if (body.ok !== true || !Array.isArray(body.resul