//reactivestate-core/com.ensody.reactivestate/shareOnDemand
shareOnDemand¶
[common]\ fun <T> Flow<T>.shareOnDemand(replay: Int = 0, context: CoroutineContext = EmptyCoroutineContext): SharedFlow<T>
Turns this Flow into a SharedFlow without requiring a CoroutineScope (unlike shareIn).
The underlying Flow is only collected while there is at least one collector. When nobody collects, this is safe for garbage collection.
Normally you’d use this together with callbackFlow, for example. Alternatively you can construct a SharedFlow directly via sharedFlow.