<commit_before>var restify = require('restify');

var server = restify.createServer({
  name: 'Oboe JS Example'
});

server.get('/pairs', function (req, res, next) {

  res.header('Content-Type', 'application/json');

  function sendPairs(res) {
    var numPairs = Math.floor(((Math.random()*5)+1));
    console.log('Number of Pairs: ' + (numPairs+1));

    for(var i = 0; i <= numPairs; i++) {
      var pair = [
        Math.floor(((Math.random()*1000)%100)+1),
        Math.floor(((Math.random()*1000)%100)+1)
      ];

      console.log(pair);
      res.write(JSON.stringify(pair) + ',');
    }

    return true;
  }

  res.write('[');

  for(var i = 0; i < 25; i++) {
    var seconds = Math.floor(((Math.random()*10000)%3000)+1000);
    console.log('Waiting: ' + seconds);

    setTimeout(sendPairs(res), seconds);
  }

  res.write('[0,0]]');
  res.end();
  return next();
});

server.listen(9000);<commit_msg>proper timeouts<commit_after>var restify = require('restify');

var server = restify.createServer({
  name: 'Oboe JS Example'
});

// Quick route to send an sample number of pairs over a period of time
server.get('/pairs', function (req, res, next) {
  numSent = 0;

  // Send Header
  res.header('Content-Type', 'application/json');

  // Write a number of pairs between 1 and 5 to the response
  // If flag is true, end the communication
  function sendPairs(res, flag) {
    var numPairs = Math.floor(((Math.random()*10)%5+1));
    console.log('Number of Pairs: ' + (numPairs+1));

    for(var i = 0; i <= numPairs; i++) {

      // Generate the pair
      var pair = [
        Math.floor(((Math.random()*1000)%100)+1),
        Math.floor(((Math.random()*1000)%100)+1)
      ];

      // Write the pair
      console.log(pair);
      res.write(JSON.stringify(pair) + ',');
      numSent++;

      // End if true
      if (flag) {
        res.write('[0,0]]');
        res.end();
        console.log('Sent: ' + numSent);
        return next();
      }
    }

    // not ending
    return flag;
  }

  // Start array of pairs
  res.write('[');

  // Queue timeouts
  for(var i = 0; i < 25; i++) {
    var seconds = Math.floor(((Math.random()*10000)%5000)+1000);
    console.log('Waiting: ' + seconds);

    setTimeout(sendPairs, seconds, res, false);
  }

  // Last Pair sent, all others must finish before this to be recieved by client
  setTimeout(sendPairs, 7000, res, true);
});

// Start Server
server.listen(9000);
{'fraction_non_alphanumeric': 0.18357289527720738, 'fraction_numerical': 0.038193018480492814, 'mean_word_length': 2.8544303797468356, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2504591', 'n_tokens_mistral': 903, 'n_tokens_neox': 828, 'n_words': 200}