<commit_before>import Mailbox from './Mailbox';

export default class ActorSystem {
  constructor(dispatcher) {
    this.dispatcher = dispatcher;
    this.actors = new Map();
  }

  actorOf(Actor, name = Actor.constructor.name) {
    if (this.actors.has(name)) {
      return this.actors.get(name);
    }

    const instance = new Actor();
    const mailbox = new Mailbox(this.dispatcher.disposable);

    this.actors.set(name, instance);
    this.dispatcher.mailboxes.add(mailbox);

    const iterator = this.spawn(async function* process(dispatcher, instance) {
      for await (const message of dispatcher) instance.receive(message);
    }, instance);

    return instance;
  }

  spawn(coroutine, ...args) {
    const iterator = coroutine(this.dispatcher, ...args);
    iterator.next();
    return iterator;
  }
}<commit_msg>use just async functions<commit_after>import Mailbox from './Mailbox';

export default class ActorSystem {
  constructor(dispatcher) {
    this.dispatcher = dispatcher;
    this.actors = new Map();
  }

  actorOf(Actor, name = Actor.constructor.name) {
    if (this.actors.has(name)) {
      return this.actors.get(name);
    }

    const instance = new Actor();
    const mailbox = new Mailbox(this.dispatcher.disposable);

    this.actors.set(name, instance);
    this.dispatcher.mailboxes.add(mailbox);

    const iterator = this.spawn(async function process(dispatcher, instance) {
      for await (const message of dispatcher) instance.receive(message);
    }, instance);

    return instance;
  }

  spawn(coroutine, ...args) {
    return coroutine(this.dispatcher, ...args);
  }
}
{'fraction_non_alphanumeric': 0.12685643564356436, 'fraction_numerical': 0.0, 'mean_word_length': 3.3940217391304346, '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': '3911996', 'n_tokens_mistral': 508, 'n_tokens_neox': 482, 'n_words': 113}