proposal-cancellation
proposal-cancellation copied to clipboard
SharedArrayBuffer's Atomics.waitAsync() primitive is in need of cancellation support in order to not obstruct GC
Implementing Atomics.waitAsync
based multithreading primitives to Emscripten WebAssembly code libraries, it was realized in https://github.com/WebAssembly/threads/issues/176 that the ability to perform memory deinitialization after having issued a Atomics.waitAsync
is severely impaired without a mechanism to cancel a waitAsync
operation.
In that thread it was suggested that maybe a future machinery to enable cancelling a Promise might help the issue and let garbage collection to happen properly, without requiring sites to wrap all their multithreaded WebAssembly content inside iframes for GC to work.
Would Promise cancellation mechanism be suitable for fixing the current Atomics.waitAsync
GC problem? Are there any rough eta estimates for Promise cancellation support to arrive in browsers? (2021? or later? or too early to tell?)
The cancellation of async operations already exists in browsers (AbortController/AbortSignal), but that implementation depends on browser-specific APIs (i.e., EventTarget) that don't exist in ECMA-262. An alternative I've proposed is #22, defining a symbol-based cancellation protocol that could be recognized in ECMA-262 and implemented on top of AbortController/AbortSignal, or in user-land code.
I plan to bring cancellation (in this protocol form) back before committee later this year.