<commit_before>var Q      = require('q'),
    spawn  = require('child_process').spawn,
    fs     = require('fs'),
    net    = require('net'),
    logger = require('winston'),
    waitForSocket = require('./wait-for-socket.js'),
    mpdConfig = require(__dirname+'/mpd-config.js');

exports.create = function(config) {
  var mpdConf = mpdConfig.create(),
      instance = {};

  instance.port = mpdConf.port;

  function waitToBeOnline() {
    return waitForSocket
              .create(instance.port)
              .connect();
  }

  function spawnMPD(fileName) {
    var deferred = Q.defer(),
        mpdProcess = spawn('/usr/local/bin/mpd', [fileName, '--no-daemon']);

    mpdProcess.on('close', function(code, signal) {
      logger.error('MPD Closed: ' + code);
    });

    mpdProcess.stdout.on('data', function(data) {
      logger.info('MPD: ' + data);
    });

    mpdProcess.stderr.on('data', function(data) {
      logger.warn('MPD: ' + data);
    });

    deferred.resolve();

    return deferred.promise;
  }

  instance.start = function() {
    return mpdConf.write(config).then(spawnMPD)
      .then(waitToBeOnline);
  };

  return instance;
};<commit_msg>Implement new MPDChildProcess object into production code<commit_after>var Q      = require('q'),
    spawn  = require('child_process').spawn,
    fs     = require('fs'),
    net    = require('net'),
    logger = require('winston'),

    waitForSocket   = require('./wait-for-socket'),
    mpdChildProcess = require('./mpd-child-process'),
    mpdConfig       = require('./mpd-config');

exports.create = function(config) {
  var mpdConf = mpdConfig.create(),
      instance = {};

  instance.port = mpdConf.port;

  function waitToBeOnline() {
    return waitForSocket
              .create(instance.port)
              .connect();
  }

  function spawnMPD(fileName) {
    return mpdChildProcess.create(fileName);
  }

  instance.start = function() {
    return mpdConf.write(config).then(spawnMPD)
      .then(waitToBeOnline);
  };

  return instance;
};
{'fraction_non_alphanumeric': 0.15771315919172005, 'fraction_numerical': 0.0, 'mean_word_length': 2.830188679245283, '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': '4695067', 'n_tokens_mistral': 657, 'n_tokens_neox': 639, 'n_words': 110}