Skip to content
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

Merged
merged 3 commits into from
May 22, 2024
Merged

feat(poc): implement poc for web workers #10916

merged 3 commits into from
May 22, 2024

Conversation

JammingBen
Copy link
Collaborator

@JammingBen JammingBen commented May 16, 2024

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 from web-client to build requests. We can still use the web-client here, just not the ClientService.

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 a self.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

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests
  • Documentation
  • Maintenance (e.g. dependency updates or tooling)

@JammingBen JammingBen self-assigned this May 16, 2024
Copy link

update-docs bot commented May 16, 2024

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.

@JammingBen
Copy link
Collaborator Author

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.

Copy link

sonarcloud bot commented May 22, 2024

@JammingBen JammingBen marked this pull request as ready for review May 22, 2024 07:47
Copy link
Member

@kulmann kulmann left a 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! 😍

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.

None yet

2 participants