You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The end-goal is drop-in integration with the Explicit Resource Management proposal (at Stage 3), with the nearer term goal of smoothing integration with tools that polyfill that.
The syntax it enables:
constfunc=()=>{// declare an instance of our wasm-bindgen'd struct, specifying that it should be cleaned up// at the end of the scope it's declared in.usingfoobar=newMyStruct();// do a bunch of stuff...}func();// When func() (or any other scope that keyword is used in) finishes, MyStruct::free is called
At the moment, Deno, Bun and Typescript >= 5.2 support the above directly; Usage without the above sugar is a little underwhelming, but probably still useful as a standardized target:
classMyStruct{free(){}// the usual wasm-bindgen methods elided for brevity[Symbol.dispose](){this.free();}}constfoo=newMyStruct();foo[Symbol.dispose]();// or, more usefully, use a disposable stack (supplied by a polyfill) to orchestrate // more elaborate resource managementconststack=newDisposableStack();constbar=stack.use(newMyStruct());constbaz=stack.use(newOtherStruct(bar));// free the above in reverse orderstack[Symbol.dispose]();
Proposed Solution
Include the [Symbol.dispose]() { this.free() } pattern on all generated classes, polyfilling via Symbol.dispose ??= Symbol("Symbol.dispose");.
Async dispose is probably irrelevant
Alternatives
It's not terribly difficult for 3rd party authors to run the generated bindings through code transformation of their own.
Motivation
The end-goal is drop-in integration with the Explicit Resource Management proposal (at Stage 3), with the nearer term goal of smoothing integration with tools that polyfill that.
The syntax it enables:
At the moment, Deno, Bun and Typescript >= 5.2 support the above directly; Usage without the above sugar is a little underwhelming, but probably still useful as a standardized target:
Proposed Solution
Include the
[Symbol.dispose]() { this.free() }
pattern on all generated classes, polyfilling viaSymbol.dispose ??= Symbol("Symbol.dispose");
.Async dispose is probably irrelevant
Alternatives
It's not terribly difficult for 3rd party authors to run the generated bindings through code transformation of their own.
Additional Context
The ecmascript proposal, for reference: https://github.com/tc39/proposal-explicit-resource-management
The text was updated successfully, but these errors were encountered: