Description
Currently communicating to a worker that work should be aborted is somewhat annoying. This is especially true for work that may be run in a synchronous loop as one can not simply send forward a MessageChannel
that signals aborting, but rather you need to send a SharedArrayBuffer
that can be synchronously read.
I'd like to propose the ability to .postMessage
an AbortSignal
so that we can communicate aborting to workers in a consistent way to aborting on the main thread. Ideally this would support the synchronous case as well (e.g. calling controller.abort()
from the original thread would synchronously update signal.aborted
in the other thread so that compute loops can simply do if (signal.aborted) { /* terminate work */ }
).
If there's interest, I would be willing to create a PR for this.