Alexander Maryanovsky
08/03/2024, 9:18 PMComputing
while the computation is in progress and Result
when it’s done?
The computation should happen on a background thread and preferably should restart when its dependencies change.Alexander Maryanovsky
08/03/2024, 9:19 PMAlexander Maryanovsky
08/03/2024, 9:21 PMyoussef hachicha
08/03/2024, 10:13 PMZach Klippenstein (he/him) [MOD]
08/03/2024, 11:50 PMproduceState
might be what you’re looking forAlexander Maryanovsky
08/04/2024, 2:44 PMZach Klippenstein (he/him) [MOD]
08/04/2024, 4:13 PMTaskEffect
you were telling me about?Chuck Jazdzewski [G]
08/06/2024, 3:56 PMproduceState
is that it requires going though composition to restart. This means that, not only does it restart composition (which requires a rendezvous with the main thread), it is a frame behind as it doesn't restart the producer until after the next composition. This means that the results are often a frame or two late. Even if we would automatically calculate the keys, it wouldn't fix this issue, the value would still be late. Ideally, for a long running producer, the producer should restart independent of composition, and only trigger composition when a new value is produced.
In JavaScript frameworks that use signals (such as Qwik) what you describe is referred to as a Task
and the task produces a signal that is dependent on any signals that are read as part of producing the new value. The task is restarted whenever any of the dependent signals change. In Compose that would translate into a state where the producer for the state is run in a coroutine with a (readonly?) snapshot that tracks state reads. It would automatically reproduce the result if any of the states read change. If the values change during computation, the producer coroutine would (optionally?) be cancelled and restarted. A consistent producer would only produce a state if the states it read are unmodified (I am thinking a consistent producer would be the default as the failure to apply would be rare and if it does occur often a stale value would not be valid; handling potentially stale values would require planning for the consumer).
Task
is a bit of an overloaded term but this seems to describe what you want here.Alexander Maryanovsky
08/06/2024, 4:01 PMChuck Jazdzewski [G]
08/06/2024, 9:55 PMsnasphotFlow()
seems to be able to most of what you want now. What about snapshotFlow()
doesn't work in your scenario? I have some ideas but I want to make sure I am not just projecting my opinion on your use case. Second, does your case need to be on another thread or would a callback on the main thread be sufficient?Alexander Maryanovsky
08/07/2024, 4:53 AM