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

Switched to a new Actor implementation #44

Merged
merged 8 commits into from
Jul 28, 2024
Merged

Switched to a new Actor implementation #44

merged 8 commits into from
Jul 28, 2024

Conversation

ogaclejapan
Copy link
Contributor

@ogaclejapan ogaclejapan commented Jul 28, 2024

Improve actor disposing to avoid ClosedSendChannelException.

The issue arises when the code is executed in a specific sequence, leading to a reference to an already closed query.

1. caller:  client.getQuery(key)
2. swr-cache: query.close()
3. caller: query.start() // <-- ClosedSendChannelException !!!

In the current implementation of the Actor, the Actor is only started when onLaunchedEffect is executed. As a result, there is a delay between retrieving the query and starting the Actor, which exposed a design flaw.

To address this issue, we needed to carefully examine the implementation of the Actor and ensure that it aligns with the following well-defined requirements:

  1. Accurately return the appropriate query (whether new or reused) when called upon.
  2. Independently carry out the disposal process of the Actor, without being influenced by the order of execution between concurrent operations.

In the new design, query.start is decoupled from launchIn(scope), effectively synchronizing the Actor state at the timing of the getQuery call. This mechanism allows for the detection of state differences even within delayed disposal processes on the main thread, ensuring safe closure.

@ogaclejapan ogaclejapan added the breaking-change Breaking Changes label Jul 28, 2024
@ogaclejapan ogaclejapan self-assigned this Jul 28, 2024
@ogaclejapan ogaclejapan merged commit 5c9cbd2 into main Jul 28, 2024
1 check passed
@ogaclejapan ogaclejapan deleted the improve-actor branch July 28, 2024 06:59
@github-actions github-actions bot mentioned this pull request Jul 28, 2024
ogaclejapan added a commit that referenced this pull request Aug 17, 2024
The scheduling logic for batch tasks, originally implemented in the SwrCache class, has been extracted into a new class
called BatchScheduler. This separation of concerns allows for better maintainability and reusability of code.

Additionally, the SwrCachePolicy class has been moved to its own file. This separation of classes into individual files
makes the codebase more navigable and easier to understand.

refs: #44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Breaking Changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant