Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Add retained caching for paging flows #1763

Merged
merged 1 commit into from
Apr 29, 2024
Merged

Conversation

chrisbanes
Copy link
Owner

@chrisbanes chrisbanes commented Feb 17, 2024

We now use a rememberRetainedCoroutineScope to keep a CoroutineScope running in a retained state. This allows to then keep a retained cachedIn paging flow running too.

github-merge-queue bot pushed a commit to slackhq/circuit that referenced this pull request Feb 17, 2024
This PR manually calls `RememberObserver` calls as appropriate when used
in `rememberRetained`. The semantics of `rememberRetained` are obviously
different to `remember`, so we call them at different times:

- `onRemembered` will be called the first time that the retained item is
first `remember`ed. The difference here is that we will **not** call
`onRemembered` again once a the object is restored and remembered back
into composition.
- `onForgotten` will be called only once the retained state is cleared
from both composition and any retained registries.
- Thus, the logical lifecycle is maintained of created (`onRemembered`
called), through to being no longer retained/remembered (`onForgotten`
called).
- We do not call `onAbandoned` as retained state doesn't meet the
contract of the function.

I did think about creating a `RetainedObserver` interface, but figured
that using the existing `RememberObserver`, even with slightly different
semantics, is a better solution.

This has a variety of use-cases, but I have been playing around with a
`rememberRetainedCorotineScope` in Tivi:
chrisbanes/tivi#1763
@chrisbanes chrisbanes force-pushed the cb/retained-coroutine-scope branch 2 times, most recently from 6c4c502 to 3f2cc71 Compare March 21, 2024 10:42
@chrisbanes chrisbanes force-pushed the cb/retained-coroutine-scope branch from 3f2cc71 to ab77b38 Compare April 19, 2024 10:23
@chrisbanes chrisbanes changed the title [WIP] Experiments with rememberRetainedCoroutineScope Add retained caching for paging flows Apr 19, 2024
@chrisbanes chrisbanes marked this pull request as ready for review April 19, 2024 10:23
@chrisbanes chrisbanes enabled auto-merge (squash) April 19, 2024 10:24
@chrisbanes chrisbanes disabled auto-merge April 19, 2024 10:31
We now use a `rememberRetainedCoroutineScope` to keep a CoroutineScope
running in a retained state. This allows to then keep a retained
`cachedIn` paging flow running too.
@chrisbanes chrisbanes force-pushed the cb/retained-coroutine-scope branch from ab77b38 to 3bdef19 Compare April 29, 2024 08:38
@chrisbanes chrisbanes enabled auto-merge (squash) April 29, 2024 08:38
@chrisbanes chrisbanes merged commit 0c740e5 into main Apr 29, 2024
7 checks passed
@chrisbanes chrisbanes deleted the cb/retained-coroutine-scope branch April 29, 2024 08:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant