Skip to content

Conversation

@AntonioVentilii
Copy link
Collaborator

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

  • Create worker ID on worker initialization.
  • Send always the worker ID with the message.

Tests

Since we are here, we add tests.

@AntonioVentilii AntonioVentilii marked this pull request as ready for review November 14, 2025 14:57
@AntonioVentilii AntonioVentilii requested a review from a team as a code owner November 14, 2025 14:57
Copilot AI review requested due to automatic review settings November 14, 2025 14:57
Copy link
Contributor

Copilot AI left a 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 WorkerId type and WithoutWorkerId<T> utility type for type safety
  • Generated unique worker ID using crypto.randomUUID() on worker initialization
  • Modified postMessage to 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.

@AntonioVentilii AntonioVentilii force-pushed the feat-frontend/Add-worker-ID-to-AppWorker-class branch from 4da3ba6 to 9064951 Compare November 14, 2025 15:57
@AntonioVentilii AntonioVentilii added this pull request to the merge queue Nov 17, 2025
Merged via the queue into main with commit 5d27048 Nov 17, 2025
79 checks passed
@AntonioVentilii AntonioVentilii deleted the feat-frontend/Add-worker-ID-to-AppWorker-class branch November 17, 2025 08:30
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.

2 participants