-
Notifications
You must be signed in to change notification settings - Fork 9
Use using for cycle tracker #1434
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
Conversation
|
Changes look bigger than they are. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, maybe would be nice to have a unit test on the cycletracker itself but i think the overall tests give us enough coverage.
| exit(k: K) { | ||
| this.partial.delete(k); | ||
| return { | ||
| [Symbol.dispose]: () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just realised, does Firefox support Symbol.dispose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't currently have any polyfills (e.g. babel) in our main building pipeline, and would think the platform needs to support the feature translated by typescript. It looks like this resource management API is still not in release on Firefox, and unsupported on Safari https://caniuse.com/mdn-javascript_statements_using
We could 1) investigate polyfilling this feature for browsers, 2) only use these features in Deno components, or 3) avoid using using, edit: 4) or only support browsers that implement this feature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: Looks like the TypeScript compiler tsc translates the using functionality to non-"using" JS, but we use esbuild in most cases (shell, deno-web-test, jumble->vite->esbuild) which transparently copies over using functionality, requiring runtime support. We could explore esbuild plugins to translate this, or switch to using tsc for compiling (a larger lift)
|
Jordan modified the esbuild parameters to handle using there (generating the disposable invocation code), and then incorporated parts of core.js to provide the polyfill for Symbol.disposable. |
As of Typescript 5.2, there's a
usingkeyword that will automatically dispose the object when it comes off the stack.This simplifies some exception handling that would otherwise be necessary to ensure these objects are cleaned up.
Switch over the CycleTracker to use this functionality.
We could probably do the same for transactions (there's an
Symbol.asyncDisposefor that), to either avoid atx.commit(), or if we implemented a rollback, it could happen there instead.Summary by cubic
Updated CycleTracker to use the new TypeScript 5.2
usingkeyword for automatic resource cleanup, reducing manual exception handling and making cycle detection code simpler.usingfor automatic disposal.