Here’s a very naive totally unsafe example of how ...
# coroutines
m
Here’s a very naive totally unsafe example of how it should work.
send(…)
will block untill all flows have processed the sent element. Is there something like that already?
d
You could maintain a list of rendezvous channels (protected by
Mutex
), then return
consumeAsFlow()
in
receiveAsFlow()
.
What should happen if a consumer calls
receiveAsFlow
calls when
send
is suspended?
m
receiveAsFlow
merely creates a new
Flow
. It’s not even suspending.
I’ve opened a new issue for this feature with new approach 🙂 https://github.com/Kotlin/kotlinx.coroutines/issues/1901
Channels can’t solve this issue. Channels never wait for for a value to be processed by the consumer. They only wait for retrieval.
d
Flows cannot solve this either. You probably want a custom actor or something along those lines.
Especially since "processed" will have to be concretely defined between the sender and receiver.
m
A regular
Flow
already has exactly that behavior:
emit()
suspends until the value collection is completed downstream. It just doesn’t work for broadcasts.
m
Very interesting, thank you!