<commit_before>
var events = require('events'),
    createClient = require('./swf').createClient,
    async = require('async'),
    util = require('util');

/**
 * Abstract class for the Amazon Simple Workflow polling mechanism
 * @constructor
 * @augments events.EventEmitter
 * @abstract
 * @fires Poller#poll
 * @fires Poller#error
 */
var Poller = exports.Poller = function(params, swfClient) {

   events.EventEmitter.call(this);

   /**
    * Configuration object for the poller
    * @private
    * @type Object
    */
   self = this
   this.config = params.config || params;
   this.taskLimitation = params.limit || 64;
   this.taskQueue = async.queue(function(queueFunc, callback){
    queueFunc(callback);
   }, this.taskLimitation);
   this.taskQueue.drain = function(){
    self.start();
   };
   this.taskQueue.saturated = function(){
    self.stop();
   };

   /**
    * Client Instance to access Simple Workflow (from aws-sdk)
    * @private
    * @type AWS.SimpleWorkflow
    */
   this.swfClient = swfClient || createClient();

   /**
    * Name of the polling method to call on the swfClient
    * @private
    * @type string
    * @abstract
    */
   this.pollMethod = "abstract";
};

util.inherits(Poller, events.EventEmitter);

/**
 * Start the poller
 */
Poller.prototype.start = function() {
   this.stop_poller = false;
   this.poll();
};

/**
 * Stops the poller<br />
 * IMPORTANT: the poller won't be stopped immediately !<br />
 * It will wait for the end of the long query poll before leaving, so that no ActivityTask gets "lost".
 */
Poller.prototype.stop = function () {
   this.stop_poller = true;
};

/**
 * Poll Amazon WebService for new tasks in a loop.
 * When a new task is received, will emit a 'activityTask' event.
 * @private
 */
Poller.prototype.poll = function () {

   if (this.stop_poller) {
      //console.log(this.config.identity + ": stop_poller, quitting properly...");
      return;
   }

   /**<commit_msg>Separate pause and stop behavior<commit_after>
var events = require('events'),
    createClient = require('./swf').createClient,
    async = require('async'),
    util = require('util');

/**
 * Abstract class for the Amazon Simple Workflow polling mechanism
 * @constructor
 * @augments events.EventEmitter
 * @abstract
 * @fires Poller#poll
 * @fires Poller#error
 */
var Poller = exports.Poller = function(params, swfClient) {

   events.EventEmitter.call(this);

   /**
    * Configuration object for the poller
    * @private
    * @type Object
    */
   self = this
   this.config = params.config || params;
   this.pause_poller = false;
   this.taskLimitation = params.limit || 64;
   this.taskQueue = async.queue(function(queueFunc, callback){
    queueFunc(callback);
   }, this.taskLimitation);
   this.taskQueue.drain = function(){
    self.resume();
   };
   this.taskQueue.saturated = function(){
    self.pause();
   };

   /**
    * Client Instance to access Simple Workflow (from aws-sdk)
    * @private
    * @type AWS.SimpleWorkflow
    */
   this.swfClient = swfClient || createClient();

   /**
    * Name of the polling method to call on the swfClient
    * @private
    * @type string
    * @abstract
    */
   this.pollMethod = "abstract";
};

util.inherits(Poller, events.EventEmitter);

/**
 * Resume the poller
 */
Poller.prototype.resume = function() {
   this.pause_poller = false;
   this.poll();
};

/**
 * Pause the poller
 */
Poller.prototype.pause = function() {
   this.pause_poller = true;
};

/**
 * Start the poller
 */
Poller.prototype.start = function() {
   this.stop_poller = false;
   this.poll();
};

/**
 * Stops the poller<br />
 * IMPORTANT: the poller won't be stopped immediately !<br />
 * It will wait for the end of the long query poll before leaving, so that no ActivityTask gets "lost".
 */
Poller.prototype.stop = function () {
   this.stop_poller = true;
};

/**
 * Poll Amazon WebService for new tasks in a loop.
 * When a new task is received, will emit a 'activityTask' event.
 * @private
 */
Poller.prototype.poll = function () {

   if (this.stop_poller || this.pause_poller) {
      //console.log(this.config.identity + ": stop_poller, quitting properly...");
      return;
   }

   /**
{'fraction_non_alphanumeric': 0.13793103448275862, 'fraction_numerical': 0.0009512485136741974, 'mean_word_length': 3.052023121387283, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1916580', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1301, 'n_words': 350}