<commit_before>'use strict';

var domain = require('domain');
var EE = require('events').EventEmitter;

var eos = require('end-of-stream');

function asyncDone(fn, done){
  function onSuccess(result){
    return done(undefined, result);
  }

  function onError(error){
    return done(error);
  }

  var d = domain.create();
  d.on('error', onError);
  var domainBoundFn = d.bind(fn);

  function asyncRunner(){
    var result = domainBoundFn(done);

    if(result && result instanceof EE){
      d.add(result);
      eos(result, { error: false }, onSuccess);
      return;
    }

    if(result && typeof result.then === 'function'){
      result.then(onSuccess, onError);
      return;<commit_msg>use .once instead of .on - fixes #1<commit_after>'use strict';

var domain = require('domain');
var EE = require('events').EventEmitter;

var eos = require('end-of-stream');

function asyncDone(fn, done){
  function onSuccess(result){
    return done(undefined, result);
  }

  function onError(error){
    return done(error);
  }

  var d = domain.create();
  d.once('error', onError);
  var domainBoundFn = d.bind(fn);

  function asyncRunner(){
    var result = domainBoundFn(done);

    if(result && result instanceof EE){
      d.add(result);
      eos(result, { error: false }, onSuccess);
      return;
    }

    if(result && typeof result.then === 'function'){
      result.then(onSuccess, onError);
      return;
{'fraction_non_alphanumeric': 0.15211267605633802, 'fraction_numerical': 0.0007042253521126761, 'mean_word_length': 3.4826498422712935, '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': '1281149', 'n_tokens_mistral': 454, 'n_tokens_neox': 439, 'n_words': 111}