-
-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat - Shared Workers #402
base: master
Are you sure you want to change the base?
Conversation
It looks like shared workers don't have a terminate method at all. The biggest open question is how to do a runtime check against worker. This is needed in order to adapt to the API.
It looks like that eliminates type errors. I wonder why it's not needed.
@andywer I've made some progress on this one. The main part I'm not understanding has to do with the proxying at I noticed shared workers don't have a |
Thanks for this massive contribution, @bebraw! I will have a more in-depth look tomorrow and will also try to explain a few things about the code (I know, it's pretty complex and hard to read in some places). Regarding the formatting… I didn't set up a prettier config, but tslint is set up. So as far as I am concerned, if tslint doesn't complain it should be fine. |
Yeah, it's possible we might have to revert the prettier formatting changes. I know tslint isn't very opinionated when it comes to formatting. |
@bebraw Especially the semicolons really bloat the diff and make it hard to read. Is there any easy way for you to strip the semicolons? Maybe add some preliminary prettier config or so. |
Sure, let me do that. 👍 |
@andywer It should be cleaner. |
Yes, but it was only applied to some files, not all of them. Was that expected? |
@andywer Let me check the remaining ones. :) |
I figured out `worker` code can contain a bit of branching to take shared workers into account. This eliminates both implementation and test code. Note that tests don't pass at the moment!
I was able to simplify the code somewhat based on your comments. I realized it's possible to reuse the existing Note that the shared worker related tests don't pass at the moment but those might be fixed as we resolve the last major issue of proxying shared workers. |
Great stuff!
Is there any way I can help? |
A bit simpler this way.
There is one issue: ~/threads.js feat/shared-workers npm run test:puppeteer:basic ✔ system Node
> [email protected] test:puppeteer:basic /threads.js
> puppet-run --plugin=mocha --bundle=./test/workers/:workers/ --serve=./bundle/worker.js:/worker.js ./test/*.chromium*.ts
✔ Bundling done.
threads in browser
1) can spawn and terminate a thread
ReferenceError: SharedWorker is not defined
at Object.isWorkerRuntime (src/worker/implementation.browser.ts:16:31)
at Object.<anonymous> (src/worker/index.ts:202:97) For a reason I don't understand yet, The second issue had to do with proxy typing but I managed to solve that one so above is what remains. It's possible I missed something in the code flow and maybe more code is needed. |
I have been thinking about it on and off since yesterday, but that's also weird for me… I don't see how, but maybe the worker is somehow run as a page script, not as a worker? And always helpful: Have you tried running |
Thanks, that was a good tip. I found out that the check against Instead of erroring, now the shared worker related tests don't complete. It seems that |
It seems it times out at I think it might be related to the way we're handling |
It definitely seems that we're missing |
What is the status of this feature? |
@pubkey Great question. Not sure what the exact status is, but it's definitely marked as "work in progress" (as in not yet "ready for review"). |
It turns out my client doesn't need the feature anymore (different approach now). @pubkey If you want to complete the work, that would be great. |
Work in progress
The purpose of this PR is to add support for Shared Workers to threads.js. So far I've done the following:
get-expose.ts
helper to allow a separateexpose
for the shared casesSharedWorker
from threads.jsAs I wasn't sure which formatting convention is used on the project, it seems my editor applied some default Prettier formatting. I can fix this later after you let me know of your preference.
I don't expect the code to work yet but there's enough to see the direction.
Closes #401.