You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I named the property endpoint to take into account that in the case of shared workers, it's not a worker but a port instead, and Comlink calls this Worker|MessagePort hybrid type "endpoint".
The name endpoint is bad. We should use a symbol instead maybe with Symbol.for.
As wrap(endpoint) is a Proxy wrapped.endpoint = endpoint; will not work as expected to properly implement this we would need to wrap wrap(endpoint) in a new Proxy. (Problem 1: I'm not convinced that this code works; Problem 2: A non breaking change in comlink could break this)
Thanks for the quick reply! I implemented the changes you requested: It now uses Symbol.for('endpoint') for accessing the endpoint, and it now wraps the Comlink Proxy in another proxy to make sure the access to the endpoint isn't intercepted by the Comlink Proxy.
I also did a rudimentary local test of this version, by building the package and copying it into a Vite project where I logged the Worker instance and used the terminate() function on it. It worked on my machine. Let me know if I can provide any proof or unit test or reproduction of it working.
However, I don't necessarily need this code to be the final solution. This PR is just a proposal to get the ball rolling. If you have any other ideas how to solve this, I'm all for it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #111, by allowing the following:
Which gets transformed into the following code (whitespace adjusted for readability):
I named the property
endpointto take into account that in the case of shared workers, it's not a worker but a port instead, and Comlink calls this Worker|MessagePort hybrid type "endpoint".