vite-plugin-comlink icon indicating copy to clipboard operation
vite-plugin-comlink copied to clipboard

Access to un-wrapped worker instance

Open carlobeltrame opened this issue 2 years ago • 2 comments

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?

carlobeltrame avatar Jun 28 '23 10:06 carlobeltrame

Looking for a way to get the terminate method too.

Tsury avatar Feb 29 '24 10:02 Tsury

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.

carlobeltrame avatar May 16 '24 15:05 carlobeltrame