[IJPL-215413] Add flow-based APIs to RegistryValue #3291
Closed
+32
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds four Flow-based APIs to RegistryValue to allow users to observe and react to value changes in flow-based scenarios, and allowing easy integration in Compose-based UIs:
The existing listener-based API unfortunately cannot be used for this purpose, as wrapping it in callbackFlow causes an exception to be thrown at runtime. I used
IdleTrackeras my implementation reference, but have some slightly different choices:IdleTrackerdoesn't because it only deals inUnitemissions)IdleTracker, we have functions instead of properties, since these involve creating a coldFlowon each invocation, and we don't want to obfuscate thatFlows and notSharedFlows, as the mapping and distinct operations create cold flows and it is then up to the user toshareIn/stateInbased on their needsIdleTrackerwe useDROP_OLDESTfor the flow backpressure (we assume users are primarily interested in the most recent values, not the oldest), and we do not provide a replay as some users may not want/need it — and they will be able to easily useonStartto provide one, or will be required to pass an initial value tostateInanywayRegistryValueAPIs when it comes to parsing the underlying strings to other types: it will just throw and fail if it is not possibleI opted against providing a
Colorflow for now, as it can be trivially added later if needed, but am also expecting the flow-based APIs will be mostly useful for Compose UI surfaces. These would not particularly benefit from getting an AWT color anyway, and would probably prefer to parse strings to Compose colours using Jewel APIs.