{"size": 1296, "ext": "js", "max_stars_repo_path": "example/lib/local-component/index.js", "max_stars_repo_name": "happner/happner-cluster", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "example/lib/local-component/index.js", "max_issues_repo_name": "happner/happner-cluster", "max_issues_repo_issues_event_min_datetime": "2016-11-14T13:01:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-20T11:36:08.000Z", "max_forks_repo_path": "example/lib/local-component/index.js", "max_forks_repo_name": "happner/happner-cluster", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 179, "max_forks_count": null, "avg_line_length": 24.4528301887, "max_line_length": 81, "alphanum_fraction": 0.611882716}
module.exports = LocalComponent;

function LocalComponent() {}

LocalComponent.prototype.start = function($happn, callback) {
  var _this = this;

  // interval call method into cluster
  // (remote-component only "implemented" when other cluster members are running)
  var sequence = 0;
  this.interval = setInterval(function() {
    !(function(seq) {
      $happn.data.set('/something/here', { seq: seq });

      $happn.exchange['remote-component']
        .method1(seq)
        .then(function(result) {
          $happn.log.info('%d reply %s', seq, result);
        })
        .catch(function(error) {
          $happn.log.error('%d error %s', seq, error.toString());
        });
    })(sequence++);
  }, 900);

  // subscribe to cluster events
  $happn.event['remote-component'].on(
    'event',
    function(data) {
      $happn.log.info('event from %s', data.origin);
    },
    function(e, subscriptionId) {
      if (e) {
        $happn.log.error('failed to subscribe to event');
        return;
      }
      _this.subscriptionId = subscriptionId;
    }
  );

  callback();
};

LocalComponent.prototype.stop = function($happn, callback) {
  clearInterval(this.interval);

  if (this.subscriptionId) {
    $happn.event['remote-component'].off(this.subscriptionId);
  }

  callback();
};
