<commit_before>'use strict'

import _debug from 'debug'
const debug = _debug('chiffchaff:Task')

import Promise from 'bluebird'
import {EventEmitter} from 'events'

Promise.config({cancellation: true})

let counter = 0

export default class Task extends EventEmitter {
  constructor () {
    super()
    this._id = ++counter
    if (Task._reporter) {
      Task._reporter.acceptTask(this)
    }
  }

  static set reporter (value) {
    Task._reporter = value
  }

  get name () {
    return `${this.constructor.name}#${this._id}`
  }

  get promise () {
    return this._promise
  }

  start () {
    debug(`Starting ${this}`)
    this.emit('start')
    this._promise = this._start()
    return this._promise
      .then(res => this._onResolve(res), err => this._onReject(err))
      .finally(() => {
        if (this._promise.isCancelled()) {
          this._onCancel()
        }
      })
  }

  cancel () {
    debug(`Cancelling ${this}`)
    this._promise.cancel()
  }

  isCancelled () {
    return this._promise.isCancelled()
  }

  _start () {
    throw new Error('Method is abstract')
  }

  _onResolve (res) {
    debug(`${this} completed`)
    this.emit('done', res)
    this.emit('end', null, res)
    return res<commit_msg>Safety check<commit_after>'use strict'

import _debug from 'debug'
const debug = _debug('chiffchaff:Task')

import Promise from 'bluebird'
import {EventEmitter} from 'events'

Promise.config({cancellation: true})

let counter = 0

export default class Task extends EventEmitter {
  constructor () {
    super()
    this._id = ++counter
    if (Task._reporter) {
      Task._reporter.acceptTask(this)
    }
  }

  static set reporter (value) {
    Task._reporter = value
  }

  get name () {
    return `${this.constructor.name}#${this._id}`
  }

  get promise () {
    return this._promise
  }

  start () {
    debug(`Starting ${this}`)
    this.emit('start')
    this._promise = this._start()
    return this._promise
      .then(res => this._onResolve(res), err => this._onReject(err))
      .finally(() => {
        if (this._promise.isCancelled()) {
          this._onCancel()
        }
      })
  }

  cancel () {
    debug(`Cancelling ${this}`)
    this._promise.cancel()
  }

  isCancelled () {
    return (this._promise && this._promise.isCancelled())
  }

  _start () {
    throw new Error('Method is abstract')
  }

  _onResolve (res) {
    debug(`${this} completed`)
    this.emit('done', res)
    this.emit('end', null, res)
    return res
{'fraction_non_alphanumeric': 0.14923572003218022, 'fraction_numerical': 0.0008045052292839903, 'mean_word_length': 2.7738998482549317, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5849256', 'n_tokens_mistral': 840, 'n_tokens_neox': 830, 'n_words': 179}