Skip to content

Comments

Added access to Worker's terminate method when run through comlink-loaded#487

Closed
aelgasser wants to merge 3 commits intoGoogleChromeLabs:masterfrom
aelgasser:master
Closed

Added access to Worker's terminate method when run through comlink-loaded#487
aelgasser wants to merge 3 commits intoGoogleChromeLabs:masterfrom
aelgasser:master

Conversation

@aelgasser
Copy link

When workers are loaded through comlink-loader there is no way to access the underlying Worker object through the proxy returned by comlink-loader and terminate it.

This patch maps a terminate method on the proxy to the worker's terminate method.

proxy[Comlink.releaseProxy]()is not enough in the case of Web Workers as the worker is not terminated only its endpoint if any is closed.

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@aelgasser
Copy link
Author

@googlebot I fixed it.

2 similar comments
@aelgasser
Copy link
Author

@googlebot I fixed it.

@aelgasser
Copy link
Author

@googlebot I fixed it.

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@surma
Copy link
Collaborator

surma commented Aug 24, 2020

A proxy doesn’t necessary sit on top of a Worker. It is often just wrapping a MessagePort and therefore has no knowledge of the Worker. In some scenarios, Comlink is used without a Worker being involved at all (e.g. in the iframe use-case). Additionally, apart from terminate() sometimes not existing und the underlying, wrapped primitive, there are often multiple proxies from the same worker, and being able to call terminate() on one of the proxies would leave the other proxies in a dysfunctional state.

I think your desire to get access to the worker is valid, but should be a bug on comlink-loader, rather than here.

I’m closing this, but feel free to re-open if you disagree.

@surma surma closed this Aug 24, 2020
@aelgasser
Copy link
Author

It makes sense and I was thinking, too, it should be in comlink-loader. And rethinking about it and the code I put, it's also adding an unnecessary dependancy on Worker.

I'm going to submit a pull request to comlink-loader then to solve the issue.

@aelgasser
Copy link
Author

@surma here is the pr GoogleChromeLabs/comlink-loader#27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants