{"size": 970, "ext": "js", "max_stars_repo_path": "lib/tasks/start.js", "max_stars_repo_name": "doowb/node-embr-client", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lib/tasks/start.js", "max_issues_repo_name": "doowb/node-embr-client", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/tasks/start.js", "max_forks_repo_name": "doowb/node-embr-client", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 21.5555555556, "max_line_length": 62, "alphanum_fraction": 0.5721649485}

var _ = require('lodash');
var inspect = require('util').inspect;
var subscriber = require('../subscriber');

module.exports = {
  execute: function (options, callback) {
    var emdr = this;
    options = _.extend({}, options);

    var start = new Date();
    var count = 0;
    var total = 0;

    var outputInterval = setInterval(outputMessageRate, 1000);
    var loopInterval = setInterval(loop, 200);

    subscriber.call(emdr, options);
    emdr.on('data', function (data) {
      count++;
      // emdr.emit('log', data.toString());
    });

    function outputMessageRate () {
      var timeRunning = new Date() - start;
      // var rate = count / timeRunning;
      var rate = count;
      count = 0;
      start = new Date();
      emdr.emit('log', rate);
    };

    function loop () {
      total++;

      if (total > 50) {
        clearInterval(loopInterval);
        clearInterval(outputInterval);
        return callback(null);
      }
    };

  }
};
