<commit_before>

"use strict";
let Myself = self;
class Exchange extends EventEmitter{
  constructor(){
    super();
    this.Ports = [];
  }
  Handle(Port){
    this.Ports.push(Port);
    let Me = this;
    if(this.Type === Exchange.SHARED){
      Port.start();
    }
    Port.addEventListener('message', function(e){
      let Data = e.data;
      if(!Data || !Data.EXCHANGE) return; // Ignore Non-Exchange Messages
      if(Data.Type === 'Request'){
        Data.Result = null;
        Data.Port = Port;
        Me.emit(Data.SubType, Data.Message, Data, Port);
        Me.emit('All', Data.Message, Data);
      } else if(Data.Type === 'Broadcast'){
        Me.emit(Data.SubType, Data.Message, Data, Port);
        Me.emit('All', Data.Message, Data);
      } else if (Data.Type === 'Reply'){
        Me.emit(`JOB:${Data.ID}`, Data.Message, Port);
      }
    }, false);
  }
  Send(Type, Message, Port){
    Port = Port || this.Ports[0];
    Message = Message || '';
    Port.postMessage({Type: 'Broadcast', SubType: Type, Message: Message, EXCHANGE: true});
    return this;
  }
  Request(Type, Message, Port){
    Port = Port || this.Ports[0];
    Message = Message || '';
    let Me = this;
    return new Promise(function(Resolve){
      let JobID = (Math.random().toString(36)+'00000000000000000').slice(2, 7+2);
      Me.once(`JOB:${JobID}`, Resolve);
      Port.postMessage({Type: 'Request', SubType: Type, Message: Message, ID: JobID, EXCHANGE: true});
    });
  }
  Finished(Job){
    Job.Port.postMessage({Type: 'Reply', ID: Job.ID, Message: Job.Result, EXCHANGE: true});
  }
}
Exchange = new Exchange;
Exchange.Type = null;
Exchange.SHARED = 'SHARED';
Exchange.NORMAL = 'NORMAL';
self.addEventListener('message', function Once(){
  // I am a dedicated worker
  Exchange.Type = Exchange.NORMAL;
  Exchange.Handle(Myself);
  Myself.removeEventListener('message', Once);
});
self.addEventListener('connect', function(e){
  // I am a shared worker
  Exchange.Type = Exchange.SHARED;
  Exchange.Handle(e.ports[0]);
});<commit_msg>:fire: Remove ExchangeClient.TYPE<commit_after>

"use strict";
let Myself = self;
class Exchange extends EventEmitter{
  constructor(){
    super();
    this.Ports = [];
  }
  Handle(Port){
    this.Ports.push(Port);
    let Me = this;
    if(Port.start){
      Port.start();
    }
    Port.addEventListener('message', function(e){
      let Data = e.data;
      if(!Data || !Data.EXCHANGE) return; // Ignore Non-Exchange Messages
      if(Data.Type === 'Request'){
        Data.Result = null;
        Data.Port = Port;
        Me.emit(Data.SubType, Data.Message, Data, Port);
        Me.emit('All', Data.Message, Data);
      } else if(Data.Type === 'Broadcast'){
        Me.emit(Data.SubType, Data.Message, Data, Port);
        Me.emit('All', Data.Message, Data);
      } else if (Data.Type === 'Reply'){
        Me.emit(`JOB:${Data.ID}`, Data.Message, Port);
      }
    }, false);
  }
  Send(Type, Message, Port){
    Port = Port || this.Ports[0];
    Message = Message || '';
    Port.postMessage({Type: 'Broadcast', SubType: Type, Message: Message, EXCHANGE: true});
    return this;
  }
  Request(Type, Message, Port){
    Port = Port || this.Ports[0];
    Message = Message || '';
    let Me = this;
    return new Promise(function(Resolve){
      let JobID = (Math.random().toString(36)+'00000000000000000').slice(2, 7+2);
      Me.once(`JOB:${JobID}`, Resolve);
      Port.postMessage({Type: 'Request', SubType: Type, Message: Message, ID: JobID, EXCHANGE: true});
    });
  }
  Finished(Job){
    Job.Port.postMessage({Type: 'Reply', ID: Job.ID, Message: Job.Result, EXCHANGE: true});
  }
}
Exchange = new Exchange;
self.addEventListener('message', function Once(){
  // I am a dedicated worker
  Exchange.Handle(Myself);
  Myself.removeEventListener('message', Once);
});
self.addEventListener('connect', function(e){
  // I am a shared worker
  Exchange.Handle(e.ports[0]);
});
{'fraction_non_alphanumeric': 0.17570664629488159, 'fraction_numerical': 0.012732365673542145, 'mean_word_length': 3.2010695187165776, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '6476968', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1286, 'n_words': 295}