<commit_before>const TinyEmitter = require('./tiny-emitter');

const MESSAGE_RESULT = 0;
const MESSAGE_EVENT = 1;

const RESULT_ERROR = 0;
const RESULT_SUCCESS = 1;

const DEFAULT_HANDLER = 'main';

const isPromise = o => typeof o === 'object' && typeof o.then === 'function' && typeof o.catch === 'function';

function RegisterPromise(fn) {
  const handlers = {[DEFAULT_HANDLER]: fn};
  const sendPostMessage = self.postMessage.bind(self);

  const server = new class WorkerRegister extends TinyEmitter {
    emit(eventName, ...args) {
      sendPostMessage({eventName, args: args});
      return this;
    }

    emitLocally(eventName, ...args) {
      super.emit(eventName, ...args);
    }

    operation(name, handler) {
      handlers[name] = handler;<commit_msg>Allow TransferableResponse for emit()<commit_after>const TinyEmitter = require('./tiny-emitter');

const MESSAGE_RESULT = 0;
const MESSAGE_EVENT = 1;

const RESULT_ERROR = 0;
const RESULT_SUCCESS = 1;

const DEFAULT_HANDLER = 'main';

const isPromise = o => typeof o === 'object' && typeof o.then === 'function' && typeof o.catch === 'function';

function RegisterPromise(fn) {
  const handlers = {[DEFAULT_HANDLER]: fn};
  const sendPostMessage = self.postMessage.bind(self);

  const server = new class WorkerRegister extends TinyEmitter {
    emit(eventName, ...args) {
      if (args.length == 1 && args[0] instanceof TransferableResponse) {
        sendPostMessage({eventName, args: args}, args[0].transferable);
      } else {
        sendPostMessage({eventName, args: args});
      }
      return this;
    }

    emitLocally(eventName, ...args) {
      super.emit(eventName, ...args);
    }

    operation(name, handler) {
      handlers[name] = handler;
{'fraction_non_alphanumeric': 0.13872832369942195, 'fraction_numerical': 0.006358381502890174, 'mean_word_length': 3.6910569105691056, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3776722', 'n_tokens_mistral': 548, 'n_tokens_neox': 527, 'n_words': 135}