<commit_before>import uuid from 'uuid'
import debug from 'debug'

export default class ClientPool {
  constructor (manager) {
    this._d = debug('socketeer:ClientPool')
    this._d('constructing new instance')
    this._roomManager = manager.room
    this.pool = {}
    this._reserved = {}
  }
}<commit_msg>finish client-pool<commit_after>import uuid from 'uuid'
import debug from 'debug'

export default class ClientPool {
  constructor (manager) {
    this._d = debug('socketeer:ClientPool')
    this._d('constructing new instance')
    this._roomManager = manager.room
    this.pool = {}
    this._reserved = {}
  }

  add (client, id) {
    this._d(`adding client ${id} to pool`)
    if (this.pool[id]) throw new Error(`id ${id} is already in the pool (should never happen)`)
    delete this._reserved[id]
    client.register(this)
    this.pool[id] = client
    return id
  }

  get (id) {
    this._d(`getting client with id ${id}`)
    return this.pool[id]
  }

  _generateId () {
    this._d('generating and reserving a new id')
    let id
    while (true) {
      id = uuid.v4()
      if (!this.pool[id] && !this._reserved[id]) break
    }
    this._reserved[id] = true
    this._d(`generated client pool id: ${id}`)
    return id
  }

  forEach (fn) {
    this._d('running a foreach function on pool')
    for (let client in this.pool) fn(client)
  }

  remove (id) {
    this._d(`removing client ${id} from pool`)
    delete this.pool[id]
  }

  clear () {
    this._d('clearing pool')
    this.pool = {}
  }
}
{'fraction_non_alphanumeric': 0.13731931668856767, 'fraction_numerical': 0.000657030223390276, 'mean_word_length': 2.9354005167958657, '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': '1043426', 'n_tokens_mistral': 511, 'n_tokens_neox': 497, 'n_words': 138}