I really don’t understand why SharedFlows can’t (or shouldn’t) be completable? I’ve encountered many situations were I needed a completable sharedflow. For instance imagine you’re writing a download manager that can handle multiple downloads at a time. When a download starts it progresses even if there are no subscribers to it’s progression, hence it’s hot! But on the other hand surprisingly it completes! There could be multiple subscribers for the same flow, each subscribing at different points in time. The same thing exists in RxJava and could be easily implemented in Kotlin’s Flows, there could also be an onComplete extension function for it so if anyone subscribes after its completion the onComplete will be called with no value emitted or replay values emitted first and onComplete called later.
Can’t the Kotlin team add a CompletableSharedFlow?
1 Like
The rationale for this is described in the “Error handling” section of this issue. The recommendation is to materialize the completion by emitting a special object.