<commit_before>import assert from 'power-assert'
import {EventEmitterMixin} from './event-emitter'
import {nop, mixin} from './utils'
import {CLOSED} from './constants'
import {P_RESOLVED_WITH_FALSE, P_RESOLVED_WITH_TRUE} from './constants'


// requires: implement get _isSubscribed, _subscribe(), _unsubscribe()
//
export class SpecialChan {

  constructor() {
    this._consumers = []
  }

  get canSend() {
    return false
  }

  get canSendSync() {
    return false
  }

  maybeCanSendSync() {
    return this.isClosed ? P_RESOLVED_WITH_FALSE : P_RESOLVED_WITH_TRUE
  }

  sendSync(val) {
    throw new Error(`sendSync() is unsupported by ${ this.constructor.name }`)
  }

  send(val) {
    throw new Error(`send() is unsupported by ${ this.constructor.name }`)
  }

  _addConsumer(cons, needsCancelFn, now) {
    this._consumers.push(cons)
    if (!this._isSubscribed) {
      this._subscribe(now)
    }
    return needsCancelFn ? () => this._removeConsumer(cons) : nop
  }

  _removeConsumer(cons) {
    let index = this._consumers.indexOf(cons)
    if (index >= 0) {
      this._consumers.splice(index, 1)
      if (this._consumers.length == 0 && this._isSubscribed) {
        this._unsubscribe()
      }
    }
  }
}<commit_msg>Add missing `sendError()` and `sendErrorSync()` impls to special chans<commit_after>import assert from 'power-assert'
import {EventEmitterMixin} from './event-emitter'
import {nop, mixin} from './utils'
import {CLOSED} from './constants'
import {P_RESOLVED_WITH_FALSE, P_RESOLVED_WITH_TRUE} from './constants'


// requires: implement get _isSubscribed, _subscribe(), _unsubscribe()
//
export class SpecialChan {

  constructor() {
    this._consumers = []
  }

  get canSend() {
    return false
  }

  get canSendSync() {
    return false
  }

  sendErrorSync(err) {
    throw new Error(`sendErrorSync() is unsupported by ${ this.constructor.name }`)
  }

  sendError(err, close) {
    throw new Error(`sendError() is unsupported by ${ this.constructor.name }`)
  }

  sendSync(val) {
    throw new Error(`sendSync() is unsupported by ${ this.constructor.name }`)
  }

  send(val) {
    throw new Error(`send() is unsupported by ${ this.constructor.name }`)
  }

  maybeCanSendSync() {
    return this.isClosed ? P_RESOLVED_WITH_FALSE : P_RESOLVED_WITH_TRUE
  }

  _addConsumer(cons, needsCancelFn, now) {
    this._consumers.push(cons)
    if (!this._isSubscribed) {
      this._subscribe(now)
    }
    return needsCancelFn ? () => this._removeConsumer(cons) : nop
  }

  _removeConsumer(cons) {
    let index = this._consumers.indexOf(cons)
    if (index >= 0) {
      this._consumers.splice(index, 1)
      if (this._consumers.length == 0 && this._isSubscribed) {
        this._unsubscribe()
      }
    }
  }
}
{'fraction_non_alphanumeric': 0.1310820624546115, 'fraction_numerical': 0.002178649237472767, 'mean_word_length': 3.373015873015873, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '769786', 'n_tokens_mistral': 932, 'n_tokens_neox': 904, 'n_words': 199}