-
Notifications
You must be signed in to change notification settings - Fork 39
feat(frontend): Add worker ID to AppWorker class
#10327
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(frontend): Add worker ID to AppWorker class
#10327
Conversation
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.
Pull Request Overview
This PR adds unique worker IDs to the AppWorker class to support singleton worker patterns and enable proper message routing between workers and their listeners. The worker ID is generated on initialization and automatically attached to all outgoing messages.
Key changes:
- Added
WorkerIdtype andWithoutWorkerId<T>utility type for type safety - Generated unique worker ID using
crypto.randomUUID()on worker initialization - Modified
postMessageto automatically attach worker ID to all messages - Added comprehensive test suite covering worker instantiation, messaging, and singleton behavior
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/frontend/src/lib/types/worker.ts |
Added WorkerId type alias and WithoutWorkerId<T> utility type to prevent accidental worker ID collisions |
src/frontend/src/lib/services/_worker.services.ts |
Added worker ID field, generation logic, and automatic attachment to outgoing messages |
src/frontend/src/tests/lib/services/worker.services.spec.ts |
Added comprehensive test coverage for AppWorker functionality including worker ID attachment, singleton behavior, and message handling |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
4da3ba6 to
9064951
Compare
Motivation
We will use the workers as singleton. However, there is no way of connecting automatically each posted message to their correct listener, unless we completely rewrite the way we use workers.
Furthermore, not all workers will be singleton. And some of them will be only for iOS (to try and reduce the Jetsam issue).
An alternative solution is to provide each worker with an unique ID, and wrap the listener to such ID: in case the worker is a singleton, the listener will be triggered only for the correct worker ID.
In this PR, we add the worker ID, since it can be independent of the rest of the flow.
Changes
Tests
Since we are here, we add tests.