<commit_before>define([], function () {
  'use strict';

  function Scheduler(mem, hooks) {
    hooks = hooks || {};
    this.ondebug = hooks.ondebug;
    this.onfinished = hooks.onfinished;
    this._mem = mem;
    this._processList = [];
    this.reset();
  }

  Scheduler.prototype = {
    constructor: Scheduler,

    addProcess: function (process) {
      var execEnvironment = this.newExecEnvironment(process);
      // XXX: Will be replaced by sorted insertion
      this._processList.push(execEnvironment);
    },

    newExecEnvironment: function (process) {
      return {
        pc: 1,
        process: process
      };
    },

    run: function () {
      if (!this._running) {
        this._running = true;
        this._scheduleStep();
      }
    },

    reset: function () {
      this._running = false;
      this._currentProcess = 0;
    },

    _scheduleStep: function () {
      setTimeout(this._step.bind(this));
    },

    _step: function () {
      if (!this._running) {
        return;
      }
      if (this._processList.length === 0) {
        return this.end();
      }
      var currentEnvironment = this._processList[this._currentProcess];
      var result = currentEnvironment.process(this._mem, currentEnvironment);
      this.takeAction(result);
    },

    end: function () {
      this.stop();
      this._call('onfinished');
    },

    stop: function () {
      this._running = false;
    },

    takeAction: function (result) {
      var actionName = '_onaction' + result.type;
      if (!(actionName in this)) {
        throw Error('Execution primitive unknown:', result);
      }
      return this[actionName](result);
    },

    _onactiondebug: function (baton) {
      this._processList[this._currentProcess].pc = baton.npc;
      this._call('ondebug', this._mem);
      this._scheduleStep();
    },

    _onactionend: function () {
      this._processList.splice(this._currentProcess, 1);
      this._scheduleStep();
    },

    _call: function (name) {
      var args = Array.prototype.slice.call(arguments, 1);
      var target = this[name];
      if (typeof target.apply === 'function') {
        return target.apply(this, args);
      }
    }
  };

  return {
    Scheduler: Scheduler
  };
});<commit_msg>Waiting for asynchronous promise based debug<commit_after>define([], function () {
  'use strict';

  function Scheduler(mem, hooks) {
    hooks = hooks || {};
    this.ondebug = hooks.ondebug;
    this.onfinished = hooks.onfinished;
    this._mem = mem;
    this._processList = [];
    this.reset();
  }

  Scheduler.prototype = {
    constructor: Scheduler,

    addProcess: function (process) {
      var execEnvironment = this.newExecEnvironment(process);
      // XXX: Will be replaced by sorted insertion
      this._processList.push(execEnvironment);
    },

    newExecEnvironment: function (process) {
      return {
        pc: 1,
        process: process
      };
    },

    run: function () {
      if (!this._running) {
        this._running = true;
        this._scheduleStep();
      }
    },

    reset: function () {
      this._running = false;
      this._currentProcess = 0;
    },

    _scheduleStep: function () {
      setTimeout(this._step.bind(this));
    },

    _step: function () {
      if (!this._running) {
        return;
      }
      if (this._processList.length === 0) {
        return this.end();
      }
      var currentEnvironment = this._processList[this._currentProcess];
      var result = currentEnvironment.process(this._mem, currentEnvironment);
      this.takeAction(result);
    },

    end: function () {
      this.stop();
      return this._call('onfinished');
    },

    stop: function () {
      this._running = false;
    },

    takeAction: function (result) {
      var actionName = '_onaction' + result.type;
      if (!(actionName in this)) {
        throw Error('Execution primitive unknown:', result);
      }
      return this[actionName](result);
    },

    _onactiondebug: function (baton) {
      this._processList[this._currentProcess].pc = baton.npc;
      //TODO: Add tests for checking _onactiondebug waits for debug callback
      this._call('ondebug', this._mem).then(function () {
        this._scheduleStep();
      }.bind(this));
    },

    _onactionend: function () {
      this._processList.splice(this._currentProcess, 1);
      this._scheduleStep();
    },

    _call: function (name) {
      var args = Array.prototype.slice.call(arguments, 1);
      var target = this[name];
      var result;
      if (typeof target.apply === 'function') {
        result = target.apply(this, args);
      }
      if (!(result instanceof Promise)) {
        result = Promise.resolve(result);
      }
      return result;
    }
  };

  return {
    Scheduler: Scheduler
  };
});
{'fraction_non_alphanumeric': 0.133833646028768, 'fraction_numerical': 0.0020846362309776944, 'mean_word_length': 2.3296321998612073, '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': '1498768', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1372, 'n_words': 297}