Repository navigation
Require an AbortSignal for UI lifetime - #74
Conversation
commit: |
16b0af2 to
211beb0
Compare
natemoo-re
left a comment
There was a problem hiding this comment.
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?
|
@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 Would you want to land this as is and I can take a pass at that in a follow-up? |
dreyfus92
left a comment
There was a problem hiding this comment.
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.
| @@ -0,0 +1,5 @@ | |||
| --- | |||
| '@clack/ui': patch | |||
There was a problem hiding this comment.
nit, question: should this be minor? it drops AsyncDisposable and makes signal required, and the other pending changesets are all minor
There was a problem hiding this comment.
That's a great point!
And nits always welcome. The devil is in the details after all
|
@natemoo-re absolutely!
|
211beb0 to
7207c32
Compare
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 mandatorysignalparameter which is used to shut down the render thread. Themain()loop will run until the signal is fired, at which point it will gracefully shut down and return.This also gets rid of the
RenderLoopclass which just copied over a bunch of references to use a single function.Type of change
Checklist
pnpm test)pnpm format)AI-generated code disclosure