Yes, this sound like a use case to me too.
My primary issue with
produceState
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.