Skip to content

Require an AbortSignal for UI lifetime - #74

Merged
cowboyd merged 1 commit into
mainfrom
ui-abort-signal
Nov 14, 2026
Merged

cowboyd merged 1 commit into
mainfrom
ui-abort-signal

Conversation

@cowboyd

@cowboyd cowboyd commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

The UI interface doesn't really lend itself to explicit resource management. The reason is that because it is the main() loop isn't really bound to the lexical scope. Rather, it's the determiner of the lifetime of the lexical scope in which it appears. When it's time to stop (for example you have a SIGINT), there needs to be a way to tell it to stop. Rather than make someone invent that way every time, just use the established way: AbortSignal.

Now, createUI() takes a mandatory signal parameter which is used to shut down the render thread. The main() loop will run until the signal is fired, at which point it will gracefully shut down and return.

This also gets rid of the RenderLoop class which just copied over a bunch of references to use a single function.

Type of change

  • Bug fix
  • Feature
  • Refactor (no behavior change)
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • All tests pass (pnpm test)
  • Files are formatted (pnpm format)
  • I have added/updated tests for my changes (if applicable)
  • I have added a changeset

AI-generated code disclosure

  • This PR includes AI-generated code

@pkg-pr-new

pkg-pr-new Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/bombshell-dev/ui/@clack/ui@74

commit: 7207c32

@cowboyd
cowboyd marked this pull request as ready for review November 13, 2026 19:07

@natemoo-re natemoo-re left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a usability and portability win! Wondering if we should have a default AbortController that listens to SIGINT/process.exit and if users want more control they can override it?

@cowboyd

cowboyd commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

@natemoo-re I like the idea of making it batteries included, but the only thing that makes me hesitate is that we might want to use it inside of a browser connected to xterm.js or something like that where we might not be able to assume SIGINT listeners.

@natemoo-re

Copy link
Copy Markdown
Member

@natemoo-re I like the idea of making it batteries included, but the only thing that makes me hesitate is that we might want to use it inside of a browser connected to xterm.js or something like that where we might not be able to assume SIGINT listeners.

@cowboyd ah good call out, I was not considering the process portability story. One pattern I like for that is to wrap any non-portable constructs in a system/platform interface so we can use export conditions to swap just that implementation. Basically lets us keep it as batteries included as each platform allows and centralizes the bindings in one spot.

Would you want to land this as is and I can take a pass at that in a follow-up?

@dreyfus92 dreyfus92 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does bench/helpers.ts need an update too? it looks like it still calls createUI without a signal and closes with ui[Symbol.asyncDispose](). pnpm bench fails locally on this branch, and i think ci hasn't caught it because the benchmark job is still queued on codspeed, but i might be missing something.

Comment thread .changeset/ui-abort-signal.md Outdated
@@ -0,0 +1,5 @@
---
'@clack/ui': patch

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, question: should this be minor? it drops AsyncDisposable and makes signal required, and the other pending changesets are all minor

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great point!

And nits always welcome. The devil is in the details after all

@cowboyd

cowboyd commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

@natemoo-re absolutely!

Would you want to land this as is and I can take a pass at that in a follow-up?

@cowboyd
cowboyd merged commit 5c6d3d4 into main Nov 14, 2026
8 of 10 checks passed
@cowboyd
cowboyd deleted the ui-abort-signal branch November 14, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants