comlink icon indicating copy to clipboard operation
comlink copied to clipboard

Feature Request: Expose endpoint

Open wellcaffeinated opened this issue 5 years ago • 4 comments

Related to #372

Although there are ways of getting around this, it would make things much more convenient to expose the endpoint on a proxy property. I'm using comlink-loader, which makes it impossible to access the original WebWorker instance.

What I'd love is something like:

import { endpointMarker } from 'comlink'
import myProxy from 'webpack/magic/here'

// do a long job...
myProxy.doStuff().then(...)

// oops i want to cancel
let worker = myProxy[endpointMarker]
worker.terminate()

I imagine this would be easy enough to implement. Hoping you think so too! :)

wellcaffeinated avatar Nov 22 '19 22:11 wellcaffeinated

That should definitely be easy. I am now wondering if I should remove createEndpoint and put have it as a tree-shakeable duplicateEndpoint or something and add this one in instead :thinking:

Lemme think about this for a bit.

surma avatar Nov 24 '19 15:11 surma

Any updates on this?

coolreader18 avatar May 06 '20 22:05 coolreader18

Check the pull request I just submitted https://github.com/GoogleChromeLabs/comlink/pull/487

it'll allow to simply do :

myProxy.terminate();

aelgasser avatar Aug 21 '20 17:08 aelgasser

After @surma 's review of my first attempt, I've built this one on comlink-loader https://github.com/GoogleChromeLabs/comlink-loader/pull/27.

Still waiting for it to be approved or rejected though

aelgasser avatar Sep 03 '20 06:09 aelgasser