<commit_before>var url = require('url')
var unirest = require('unirest')

function replaceHost(req, target) {
  req.url = url.parse(target)
  return req
}

function handler(error, response, body) {
  if (error) {
    return console.error('An error has occured:', error);
  }
  console.log('Request sent, status code: ' + response.statusCode)
}


// Create function
function requestFork(req, targets) {

  // Send to all forks
  targets.map(function(target){
    unirest.request(replaceHost(req, target), handler)
  })

}


var req = {
  url: 'https://api.github.com/repos/request/request',
  headers: {
    'User-Agent': 'request'
  }
}

var targets = [
  "http://mockbin.com/bin/8bbc56c6-eeb3-4d3e-b916-5a41a1e170ca",
  "http://mockbin.com/bin/356aaac4-2db1-4fb6-9e37-a44780f9f0d3"
]

requestFork(req, targets)<commit_msg>Add callback<commit_after>var url = require('url')
var unirest = require('unirest')

function replaceHost(req, target) {
  req.url = url.parse(target)
  return req
}

module.exports = function requestFork(req, targets, cb) {
  var responses = []
  var errors = []

  function handler(error, response, body) {
    if (error) {
      errors.push(error)
    }
    responses.push(response)
    if (responses.length + errors.length === targets.length) {
      cb(responses, errors)
    }
  }

  targets.map(function(target){
    unirest.request(replaceHost(req, target), handler)
  })
}

{'fraction_non_alphanumeric': 0.14875444839857652, 'fraction_numerical': 0.025622775800711744, 'mean_word_length': 3.7986348122866893, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '5353068', 'n_tokens_mistral': 524, 'n_tokens_neox': 506, 'n_words': 96}