<commit_before>(function ($) {

  //The timeout has to live in this scope
  var timeout;

  function Pollster(url, callback, options) {
    this.url = url;
    this.callback = callback || function () { return; };
    this.options = jQuery.extend({
      delay: 30 * 1000,
      on_error: function () { return; },
      on_complete: function () { return; },
      continue_on_error: false
    }, options);
    this.xhr = false;
    this.running = false;
    this.go();
  }

  if (typeof jQuery !== 'undefined') {
    jQuery.pollster = function (url, callback, options) {
      return new Pollster(url, callback, options);
    };
  }

  window.Pollster = Pollster;

  Pollster.prototype.start = function () {
    var _this = this;
    this.running = true;
    timeout = setTimeout(function () {
      _this.go();
    }, this.options.delay);
  };

  Pollster.prototype.stop = function () {
    this.running = false;
    clearTimeout(timeout);
  };

  Pollster.prototype.go = function () {
    var stop = false,
      _this = this;

    // wait for existing request to complete
    if (this.xhr) { return; }

    function cont() {
      if (stop) {
        _this.stop();
      } else {
        _this.start();
      }
    }

    //TODO: get rid of this jQuery dependecy
    this.xhr = jQuery.ajax({
      url: this.url,
      dataType: 'json',
      type: 'get',
      global: false,
      success: function (data) {
        stop = _this.callback(data);
        cont();
      },
      error: function () {
        if (_this.options.continue_on_error) {
          cont();
        }
        _this.options.on_error();
      },
      complete: function () {
        _this.xhr = false;
        _this.options.on_complete();
      }
    });

  };

}(jQuery));
<commit_msg>a tiny bit of documentation<commit_after>(function ($) {
  /*
    example:

    new Pollster(the_polling_endpoint, function() {
      if (polling_should_stop) {
        return true;
      }
    })
  */
    this.url = url;
    this.callback = callback || function () { return; };
    this.options = jQuery.extend({
      delay: 30 * 1000,
      on_error: function () { return; },
      on_complete: function () { return; },
      continue_on_error: false
    }, options);
    this.xhr = false;
    this.running = false;
    this.go();
  }

  if (typeof jQuery !== 'undefined') {
    jQuery.pollster = function (url, callback, options) {
      return new Pollster(url, callback, options);
    };
  }

  window.Pollster = Pollster;

  Pollster.prototype.start = function () {
    var _this = this;
    this.running = true;
    timeout = setTimeout(function () {
      _this.go();
    }, this.options.delay);
  };

  Pollster.prototype.stop = function () {
    this.running = false;
    clearTimeout(timeout);
  };

  Pollster.prototype.go = function () {
    var stop = false,
      _this = this;

    // wait for existing request to complete
    if (this.xhr) { return; }

    function cont() {
      if (stop) {
        _this.stop();
      } else {
        _this.start();
      }
    }

    //TODO: get rid of this jQuery dependecy
    this.xhr = jQuery.ajax({
      url: this.url,
      dataType: 'json',
      type: 'get',
      global: false,
      success: function (data) {
        stop = _this.callback(data);
        cont();
      },
      error: function () {
        if (_this.options.continue_on_error) {
          cont();
        }
        _this.options.on_error();
      },
      complete: function () {
        _this.xhr = false;
        _this.options.on_complete();
      }
    });

  };

}(jQuery));

{'fraction_non_alphanumeric': 0.14185786233911585, 'fraction_numerical': 0.003357582540570789, 'mean_word_length': 2.027095681625741, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6294738', 'n_tokens_mistral': 1140, 'n_tokens_neox': 1114, 'n_words': 258}