0no-co / gql.tada

🪄 Magical GraphQL query engine for TypeScript
https://gql-tada.0no.co
MIT License
2.52k stars 41 forks source link

feat(cli-utils): Add threading utilities for CLI #198

Closed kitten closed 4 months ago

kitten commented 4 months ago

[!NOTE] No changeset, since it's not implementing features yet.

Summary

This creates a very small utility that allows us to thread commands without much hassle. It has very limited feature support but the basic idea is that we've got two files.

The command would async-import a separate thread module, which would export an async generator function. This way we can split up the threaded task into multiple signals (unfortunately, no return value though, of course):

// in the main command file
async function mainCommand() {
  const { runThing } = await import('./thread');
  for await (const signal of runThing(...args)) {
    signal;
  }
}

The threaded file would then expose an async generator function wrapped with the threading utility:

// in the threaded file
async function* _runThing() {
  yield 'my signal';
}

export const runThing = expose(_runThing);

This is pretty poor code and doesn't handle all edge cases and only handles async generators, but it's good enough for our purposes.

Once merged with #197, we're probably ready for the last steps,

Set of changes

changeset-bot[bot] commented 4 months ago

⚠️ No Changeset found

Latest commit: 1d1d3166393ba0c969a3e3e9005f785bbd7a8f6a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR