<commit_before>import net from 'net';
import Promise from 'bluebird';
import BeanstalkdProtocol from 'beanstalkd-protocol';
import ReadQueue from './read-queue';
import {BasicReader, YamlReader} from './reader';
import {BasicWriter} from './writer';
import {commands, yamlCommands} from './commands';
import camelCase from 'lodash.camelcase';

const debug = require('debug')('beanstalkd');
const debugError = require('debug')('beanstalkd:error');
const DEFAULT_HOST = '127.0.0.1';
const DEFAULT_PORT = 11300;

export default class BeanstalkdClient {
  constructor(host, port, options) {
    this.host = host || DEFAULT_HOST;
    this.port = port || DEFAULT_PORT;
    this.options = options || {};
    this.readQueue = null;
    this.writeQueue = Promise.resolve();
    this.closed = false;
  }

  static addCommand(command, expected) {
    BeanstalkdClient.prototype[camelCase(command)] = makeCommand(
      command,
      new BasicWriter(command),
      new BasicReader(expected)
    );
  }

  static addYamlCommand(command, expected) {
    BeanstalkdClient.prototype[camelCase(command)] = makeCommand(
      command,
      new BasicWriter(command),
      new YamlReader(expected)
    );
  }

  destroy(...args) {
    return this['delete'](...args);
  }

  connect() {
    return new Promise((resolve, reject) => {
      debug('connecting to %s:%s', this.host, this.port);
      let connection = net.createConnection(this.port, this.host);

      connection.on('error', (err) => {
        this.closed = true;
        this.error = err;
        reject(err);
      });

      connection.on('connect', () => {
        debug('connected to %s:%s', this.host, this.port);
        this.connection = connection;
        this.readQueue = new ReadQueue(this.connection);
        resolve(this);
      });

      connection.on('end', () => {
        debug('connection finished');
        this.closed = true;
      });

      connection.on('close', () => {<commit_msg>Reconnection was not clearing closed property (#7)<commit_after>import net from 'net';
import Promise from 'bluebird';
import BeanstalkdProtocol from 'beanstalkd-protocol';
import ReadQueue from './read-queue';
import {BasicReader, YamlReader} from './reader';
import {BasicWriter} from './writer';
import {commands, yamlCommands} from './commands';
import camelCase from 'lodash.camelcase';

const debug = require('debug')('beanstalkd');
const debugError = require('debug')('beanstalkd:error');
const DEFAULT_HOST = '127.0.0.1';
const DEFAULT_PORT = 11300;

export default class BeanstalkdClient {
  constructor(host, port, options) {
    this.host = host || DEFAULT_HOST;
    this.port = port || DEFAULT_PORT;
    this.options = options || {};
    this.readQueue = null;
    this.writeQueue = Promise.resolve();
    this.closed = false;
  }

  static addCommand(command, expected) {
    BeanstalkdClient.prototype[camelCase(command)] = makeCommand(
      command,
      new BasicWriter(command),
      new BasicReader(expected)
    );
  }

  static addYamlCommand(command, expected) {
    BeanstalkdClient.prototype[camelCase(command)] = makeCommand(
      command,
      new BasicWriter(command),
      new YamlReader(expected)
    );
  }

  destroy(...args) {
    return this['delete'](...args);
  }

  connect() {
    return new Promise((resolve, reject) => {
      debug('connecting to %s:%s', this.host, this.port);
      let connection = net.createConnection(this.port, this.host);

      connection.on('error', (err) => {
        this.closed = true;
        this.error = err;
        reject(err);
      });

      connection.on('connect', () => {
        debug('connected to %s:%s', this.host, this.port);
        this.connection = connection;
        this.closed = false;
        this.readQueue = new ReadQueue(this.connection);
        resolve(this);
      });

      connection.on('end', () => {
        debug('connection finished');
        this.closed = true;
      });

      connection.on('close', () => {
{'fraction_non_alphanumeric': 0.14688128772635814, 'fraction_numerical': 0.005784708249496982, 'mean_word_length': 3.217391304347826, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1012590', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1150, 'n_words': 266}