CoroutineBinding
CoroutineBinding copied to clipboard
Offer for Channel can cause dropped elements
I've been using TextView.textChanges
and there's an issue with using safeOffer
and capacity = RENDEZVOUS
. If the consumer suspends before receiving again (e.g. calls delay
for whatever reason), and elements are offered during this time (i.e. more text is typed), offer
will fail, and those elements will never get sent/received.
It's not immediately obvious that capacity = RENDEZVOUS
is the default, and that safeOffer
causes the problem. The solution would be to call send
in a launch
(either from the GlobalScope
or pass a CoroutineScope
in).
Sorry too late response.
I plan that replace ReceiveChannel API with Flow. Flow API(+ buffer or broadcastIn) to the rescue this issue.
https://github.com/ReactiveCircus/FlowBinding