<commit_before>var Promise     = require('bluebird')
  , winston     = require('winston')
  , _           = require('lodash')
  ;
  
class Consumer {
  listen(server) {
    let io = require('socket.io')(server);

    io.on('connection', (socket) => {
      this.on_connection(socket);

      socket.on('disconnect', () => {
        this.on_disconnect(socket);
      });

      socket.on('msg', (msg) => {
        this.on_msg(msg);
      });
    });

    this.io = io;
  }

  on_connection(socket) {
    winston.info('a user connected');
  }

  on_disconnect(socket) {
    winston.info('user disconnected');
  }

  /*
  {
    type  : stdout | stderr,
    time  : unix tyime stamp,
    data  : buffer [data]
  }
  */
  on_msg(msg) {
    if(msg.type == 'stdout') {
      winston.info(msg.data.toString());
    }

    if(msg.type == 'stderr') {
      winston.error(msg.data.toString());
    }    
  }

  static make_server() {
    return Promise
            .try(() => {
              let server = require('http').createServer(() => {});

              return Promise
                      .fromCallback((cb) => {
                        server.listen((err) => cb(err, server));
                      });
            });
  }
}

module.exports = Consumer;

if (require.main === module) {
  Consumer
    .make_server()
    .then((server) => {
      (new Consumer()).listen(server);
    });
}<commit_msg>add server to self<commit_after>var Promise     = require('bluebird')
  , winston     = require('winston')
  , _           = require('lodash')
  ;
  
class Consumer {
  listen(server) {
    let io = require('socket.io')(server);

    io.on('connection', (socket) => {
      this.on_connection(socket);

      socket.on('disconnect', () => {
        this.on_disconnect(socket);
      });

      socket.on('msg', (msg) => {
        this.on_msg(msg);
      });
    });

    this.io = io;
    this.server = server;
  }

  on_connection(socket) {
    winston.info('a user connected');
  }

  on_disconnect(socket) {
    winston.info('user disconnected');
  }

  /*
  {
    type  : stdout | stderr,
    time  : unix tyime stamp,
    data  : buffer [data]
  }
  */
  on_msg(msg) {
    if(msg.type == 'stdout') {
      winston.info(msg.data.toString());
    }

    if(msg.type == 'stderr') {
      winston.error(msg.data.toString());
    }    
  }

  static make_server() {
    return Promise
            .try(() => {
              let server = require('http').createServer(() => {});

              return Promise
                      .fromCallback((cb) => {
                        server.listen((err) => cb(err, server));
                      });
            });
  }
}

module.exports = Consumer;

if (require.main === module) {
  Consumer
    .make_server()
    .then((server) => {
      (new Consumer()).listen(server);
    });
}
{'fraction_non_alphanumeric': 0.17380530973451327, 'fraction_numerical': 0.0, 'mean_word_length': 1.860323886639676, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '2525623', 'n_tokens_mistral': 940, 'n_tokens_neox': 898, 'n_words': 145}