-
Notifications
You must be signed in to change notification settings - Fork 156
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(poc): implement poc for web workers #10916
Conversation
Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes. |
9336a0e
to
8dcdf15
Compare
58d645f
to
8ab74c9
Compare
This is ready for a general review. I added a 2 second timer to the delete action to better visualize the process (hence this is still a draft). Once we decide if/how to move forward here I'll remove it of course. |
packages/web-pkg/src/composables/webWorkers/deleteWorker/worker.ts
Outdated
Show resolved
Hide resolved
Quality Gate passedIssues Measures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this big time! 😍
Description
This is a proof of concept web worker implementation. It implements the basic architecture (or how it could look like) and demonstrates the functionality by handling file deletion in a web worker.
I was facing mainly 2 challenges here. Firstly, a web worker lives completely isolated from the main thread, hence it has no knowledge about things like the DOM, browser storage etc. All things a worker might need must be serialized and passed into the worker. This also means that only serializable data can be passed, no functions e.g.
This hurts especially since it means we can't use the factories fromWe can still use theweb-client
to build requests.web-client
here, just not theClientService
.The second challenge I faced was that workers need to be informed about potential token updates during an ongoing worker process. This means, if a token is being updated, all potential existing web workers need to be updated with the new token.
Architecture
The implementation consists of 3 main parts. First we have the
WebWorkersStore
that acts like a registry. It can create and terminate web workers and update access tokens for all active workers. The idea behind this store is to have some instance that always knows which and how many workers are currently active.Then there are the actual workers. These are isolated
ts
files that always have aself.onmessage
method to receive data from the main thread.At last there are worker composables that are responsible for creating instances of web workers and registering them in the
WebWorkersStore
. They also handle serialization and termination after a process has finished. These composables act like an interface between the store, the actual worker and the "outside world", where they are supposed to be used. They need to be given all relevant data and a potential callback.Related Issue
long running actions
(~ Web Worker) #10855Types of changes