lib/api/content/events.js
function () {
        var self = this;

        async.waterfall([

          function (next) {
            if (!self.events) {
              self.events = new Datastore();
              self.events.ensureIndex({
                fieldName: 'event_id',
                unique: true
              });
              self.events.ensureIndex({
                fieldName: 'recorded_at',
                sparse: true
              });
              self.events.ensureIndex({
                fieldName: 'created_at',
              }, next);
            } else {
              next();
            }
          },
          function (next) {
            if (!self.keepPolling) {
              self.keepPolling = true;

              async.whilst(function () {
                return self.keepPolling;
              }, _.bind(self._emit, self), _.noop);
              next(null, true);
            } else {
              next(null, false);
            }
          },

          function (doLongPoll, next) {
            if (doLongPoll) {
              async.whilst(function () {
                return self.keepPolling;
              }, _.bind(self._longPoll, self), function (err) {
                if (err) {
                  /**
                   * Fires when an error occurs during long-polling.
                   * @event Connection#"polling.error"
                   * @type {Error}
                   * @see {@link Connection#startLongPolling}
                   */
                  self.emit('polling.error', err);
                } else if (!self.keepPolling) {
                  /**
                   * Fires when a running long-polling process ends.
                   * @event Connection#"polling.end"
                   * @see {@link Connection#stopLongPolling}
                   */
                  self.emit('polling.end');
                }
              });
            }
            next();
          }
        ], _.noop);
      }
function () {
        var self = this;

        async.waterfall([

          function (next) {
            if (!self.events) {
              self.events = new Datastore();
              self.events.ensureIndex({
                fieldName: 'event_id',
                unique: true
              });
              self.events.ensureIndex({
                fieldName: 'recorded_at',
                sparse: true
              });
              self.events.ensureIndex({
                fieldName: 'created_at',
              }, next);
            } else {
              next();
            }
          },
          function (next) {
            if (!self.keepPolling) {
              self.keepPolling = true;

              async.whilst(function () {
                return self.keepPolling;
              }, _.bind(self._emit, self), _.noop);
              next(null, true);
            } else {
              next(null, false);
            }
          },

          function (doLongPoll, next) {
            if (doLongPoll) {
              async.whilst(function () {
                return self.keepPolling;
              }, _.bind(self._longPoll, self), function (err) {
                if (err) {
                  /**
                   * Fires when an error occurs during long-polling.
                   * @event Connection#"polling.error"
                   * @type {Error}
                   * @see {@link Connection#startLongPolling}
                   */
                  self.emit('polling.error', err);
                } else if (!self.keepPolling) {
                  /**
                   * Fires when a running long-polling process ends.
                   * @event Connection#"polling.end"
                   * @see {@link Connection#stopLongPolling}
                   */
                  self.emit('polling.end');
                }
              });
            }
            next();
          }
        ], _.noop);
      }
function ( ) { var self = this ; async . waterfall ( [ function ( next ) { if ( ! self . events ) { self . events = new Datastore ( ) ; self . events . ensureIndex ( { fieldName : 'event_id' , unique : true } ) ; self . events . ensureIndex ( { fieldName : 'recorded_at' , sparse : true } ) ; self . events . ensureIndex ( { fieldName : 'created_at' , } , next ) ; } else { next ( ) ; } } , function ( next ) { if ( ! self . keepPolling ) { self . keepPolling = true ; async . whilst ( function ( ) { return self . keepPolling ; } , _ . bind ( self . _emit , self ) , _ . noop ) ; next ( null , true ) ; } else { next ( null , false ) ; } } , function ( doLongPoll , next ) { if ( doLongPoll ) { async . whilst ( function ( ) { return self . keepPolling ; } , _ . bind ( self . _longPoll , self ) , function ( err ) { if ( err ) { /**
                   * Fires when an error occurs during long-polling.
                   * @event Connection#"polling.error"
                   * @type {Error}
                   * @see {@link Connection#startLongPolling}
                   */ self . emit ( 'polling.error' , err ) ; } else if ( ! self . keepPolling ) { /**
                   * Fires when a running long-polling process ends.
                   * @event Connection#"polling.end"
                   * @see {@link Connection#stopLongPolling}
                   */ self . emit ( 'polling.end' ) ; } } ) ; } next ( ) ; } ] , _ . noop ) ; }
Start long-polling for events.
@see {@link https://developers.box.com/docs/#events-long-polling}
@fires Connection#"polling.error"
@fires Connection#"polling.end"
Start long - polling for events .