<commit_before>let fs = require('./fs.js');
let ipc = require('node-ipc');

class IPC {

  constructor(options) {
    this.logger = options.logger;
    this.socketPath = options.socketPath || fs.dappPath(".embark/embark.ipc");
    ipc.config.silent = true;
  }

  connect(done) {
    function connecting(socket) {
      ipc.of['embark'].on('connect',function() {
        done();
      });
    }

    ipc.connectTo('embark', this.socketPath, connecting);
  }

  serve() {
    ipc.serve(this.socketPath, () => {})
    ipc.server.start()

    this.logger.info(`pid ${process.pid} listening on ${this.socketPath}`);
  }

  on(action, done) {
    ipc.server.on('message', function(data, socket) {
      if (data.action !== action) {
        return;
      }
      done(data.message, socket);
    });
  }

  reply(client, action, data) {
    ipc.server.emit(client, 'message', {action: action, message: data});
  }

  once(action, cb) {
    ipc.of['embark'].once('message', function(msg) {
      if (msg.action !== action) {
        return;
      }
      cb(msg.message);
    });
  }

  request(action, data) {<commit_msg>debug console logs<commit_after>let fs = require('./fs.js');
let ipc = require('node-ipc');

class IPC {

  constructor(options) {
    this.logger = options.logger;
    this.socketPath = options.socketPath || fs.dappPath(".embark/embark.ipc");
    ipc.config.silent = true;
  }

  connect(done) {
    function connecting(socket) {
      ipc.of['embark'].on('connect',function() {
        done();
      });
    }

    ipc.connectTo('embark', this.socketPath, connecting);
  }

  serve() {
    ipc.serve(this.socketPath, () => {})
    ipc.server.start()

    this.logger.info(`pid ${process.pid} listening on ${this.socketPath}`);
  }

  on(action, done) {
    ipc.server.on('message', function(data, socket) {
      console.dir("received message");
      console.dir(action);
      console.dir(data);
      if (data.action !== action) {
        return;
      }
      done(data.message, socket);
    });
  }

  reply(client, action, data) {
    console.dir("reply message");
    console.dir(action);
    console.dir(data);
    ipc.server.emit(client, 'message', {action: action, message: data});
  }

  once(action, cb) {
    ipc.of['embark'].once('message', function(msg) {
      console.dir("once message");
      console.dir(action);
      console.dir(msg);
      if (msg.action !== action) {
        return;
      }
      console.dir('received');
      cb(msg.message);
    });
  }

  request(action, data) {
    console.dir("request message");
    console.dir(action);
    console.dir(data);
{'fraction_non_alphanumeric': 0.18167880413951706, 'fraction_numerical': 0.0, 'mean_word_length': 2.744619799139168, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6669201', 'n_tokens_mistral': 889, 'n_tokens_neox': 872, 'n_words': 145}