Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚀 Feature: a way to start a machine, send an event, then continue #325

Open
1 task done
boneskull opened this issue Jan 4, 2025 · 0 comments
Open
1 task done
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@boneskull
Copy link
Owner

Feature Request Checklist

Overview

I find myself doing stuff like:

const actor = createActor(logic);
const promise = runUntilDone(actor);
actor.send({type: 'EVENT'});
await promise;

It'd be helpful to provide an API to do this easily.

We could piggyback on AuditionOptions, e.g.:

export type AuditionOptions = {
  // ...

  /**
   * Send event immediately after starting the actor
   * (This should be generic on the logic's events, 
   * and should only apply to actors which accept events)
   */
  send?: EventObject,

  /**
   * Delay sending the event specified by {@link AuditionOptions.send}
   * by this many milliseconds. Ignored if `AuditionOptions.send` is unset
   */
  sendAfter?: number,
};

A benefit of the above is that it'd be compatible with all extant functions accepting AuditionOptions.

It pains me to note that providing a fluent API based on custom thenables could work:

await runUntilDone(actor).withEvent({type: 'EVENT'}).after(200);

I'm leaning towards hating this (especially the implementation), but could be convinced otherwise.

Open to suggestions.

Additional Info

No response

@boneskull boneskull added enhancement New feature or request help wanted Extra attention is needed labels Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant