<commit_before>'use strict';

var spawn = require('child_process').spawn;
var path = require('path');
var Stopwatch = require('timer-stopwatch');
var stdout = new (require('fixture-stdout'))();

function Hangman(timeLimit, callback) {
  if (typeof timeLimit === 'function') {
    callback = timeLimit;
    timeLimit = void 0;
  }
  if (!timeLimit) { timeLimit = 60000; }
  var monitor = spawn(path.join(__dirname, 'monitor.js'), [], { stdio: ['pipe', 1, 2] });
  stdout.capture(function() {
    monitor.stdin.write('stdout');
  });
  var timer = new Stopwatch(timeLimit, {
    refreshRate: Math.floor(timeLimit / 10) || 10
  });
  timer.on('done', callback || function() {
    process.exit(1);
  });
  timer.start();
  function heartbeat() {
    timer.reset();
    timer.start();
  }
  heartbeat.cancel = timer.stop;
  return heartbeat;
}

module.exports = Hangman;<commit_msg>callback vs monitor & stdout vs heartbeat<commit_after>'use strict';

var spawn = require('child_process').spawn;
var path = require('path');
var Stopwatch = require('timer-stopwatch');
var stdout = new (require('fixture-stdout'))();

var monitor;
function getMonitor() {
  return monitor = monitor ||
    spawn(path.join(__dirname, 'monitor.js'), [], { stdio: ['pipe', 1, 2] });
}

function Hangman(timeLimit, callback) {
  if (typeof timeLimit === 'function') {
    callback = timeLimit;
    timeLimit = void 0;
  }
  if (!timeLimit) { timeLimit = 60000; }
  var timer;
  if (callback) {
    timer = new Stopwatch(timeLimit, {
      refreshRate: Math.floor(timeLimit / 10) || 10
    });
    timer.on('done', callback || function() {
      process.exit(1);
    });
    timer.start();
  } else {
    getMonitor();
    var stdin = monitor.stdin;
    timer = {
      start: Function.prototype,
      stop: stdin.write.bind(stdin, {stop: true}),
      reset: stdin.write.bind(stdin, {reset: true})
    };
  }
  function heartbeat() {
    timer.reset();
    timer.start();
  }
  stdout.capture(heartbeat);
  var stay = function () {
    stdout.release();
    heartbeat();
    stay = heartbeat;
  };
  stay.cancel = heartbeat.cancel = timer.stop;
  return stay;
}

module.exports = Hangman;
{'fraction_non_alphanumeric': 0.16882516188714153, 'fraction_numerical': 0.012025901942645698, 'mean_word_length': 3.5251046025104604, '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': '2379562', 'n_tokens_mistral': 728, 'n_tokens_neox': 692, 'n_words': 163}