vite-plugin-comlink
vite-plugin-comlink copied to clipboard
Access to un-wrapped worker instance
According to https://github.com/GoogleChromeLabs/comlink/issues/372, in order to terminate a worker before it has completed, we need to call worker.terminate() on the worker instance. Calling it on the proxy won't work.
This package generates code like:
const proxy = wrap(
new Worker(
new URL("/src/components/print/print-react/internal:comlink:./documents/campPrint/my-custom.worker.js?type=module&worker_file", self.location)
, {type: "module"})
)
This way, accessing the new Worker(...) part is not possible. I had a look at the Comlink code, and there does not seem to be an easy way to "unwrap" the proxy.
Do you see any easy way for this package to provide access to the worker instance instead of the proxy? Or at least a way to access the terminate method on the worker instance?
Looking for a way to get the terminate method too.
I found a PR on the comlink side which would allow us to do this, but it's been unanswered since 2020... https://github.com/GoogleChromeLabs/comlink-loader/pull/27 So I created #138 to fix this on the side of vite-plugin-comlink.