lib/event-caller.js
function iterator(since) {
    if (stop) {
      return;
    }

    var attr = [];
    attr.push({ key: 'since', val: since });
    attr.push({ key: 'events', val: events });

    req({ method: 'events', endpoint: false, attr: attr }).then(function (eventArr) {

      //Check for event count on first request iteration
      if (since != 0) {
        eventArr.forEach(function (e) {
          _this.emit(lowerCaseFirst(e.type), e.data);
        });
      }

      //Update event count
      if (eventArr.length > 0) {
        since = eventArr[eventArr.length - 1].id;
      }

      //Reset tries
      tries = 0;

      setTimeout(function () {
        return iterator(since);
      }, 100);
    }).catch(function (err) {
      _this.emit('error', err);

      //Try to regain connection & reset event counter
      if (tries < retries) {
        tries++;
        setTimeout(function () {
          return iterator(0);
        }, 500);
      }
    });
  }
function iterator(since) {
    if (stop) {
      return;
    }

    var attr = [];
    attr.push({ key: 'since', val: since });
    attr.push({ key: 'events', val: events });

    req({ method: 'events', endpoint: false, attr: attr }).then(function (eventArr) {

      //Check for event count on first request iteration
      if (since != 0) {
        eventArr.forEach(function (e) {
          _this.emit(lowerCaseFirst(e.type), e.data);
        });
      }

      //Update event count
      if (eventArr.length > 0) {
        since = eventArr[eventArr.length - 1].id;
      }

      //Reset tries
      tries = 0;

      setTimeout(function () {
        return iterator(since);
      }, 100);
    }).catch(function (err) {
      _this.emit('error', err);

      //Try to regain connection & reset event counter
      if (tries < retries) {
        tries++;
        setTimeout(function () {
          return iterator(0);
        }, 500);
      }
    });
  }
function iterator ( since ) { if ( stop ) { return ; } var attr = [ ] ; attr . push ( { key : 'since' , val : since } ) ; attr . push ( { key : 'events' , val : events } ) ; req ( { method : 'events' , endpoint : false , attr : attr } ) . then ( function ( eventArr ) { //Check for event count on first request iteration if ( since != 0 ) { eventArr . forEach ( function ( e ) { _this . emit ( lowerCaseFirst ( e . type ) , e . data ) ; } ) ; } //Update event count if ( eventArr . length > 0 ) { since = eventArr [ eventArr . length - 1 ] . id ; } //Reset tries tries = 0 ; setTimeout ( function ( ) { return iterator ( since ) ; } , 100 ) ; } ) . catch ( function ( err ) { _this . emit ( 'error' , err ) ; //Try to regain connection & reset event counter if ( tries < retries ) { tries ++ ; setTimeout ( function ( ) { return iterator ( 0 ) ; } , 500 ) ; } } ) ; }
Event request loop
Event request loop