I'm confused on `trySend` vs `trySendBlocking` in...
# coroutines
u
I'm confused on
trySend
vs
trySendBlocking
in
callbackFlow
. I presume it's about backpressure right? If so, to mimic rxjava Observable, I want
trySendBlocking
right?
l
Did you read their respective KDoc? I think it's all explained there.
👎 1
e
If want to drop extra element on backpressue, you do
trySend
, to block in case of backpressue ->
trySendBlocking
👍 1
u
If I might ask, does the backpressure sort of happen right away or are there some internal buffers? From rxjava I faintly remember that yes Observable doesnt support backpressure, i.e. blocks caller, however I do remember there being some 64 sized buffer in it or something like that, so it should not happen that often
e
Default is 64, you can configure with
buffer(n)
u
so callbackflow with trySendBlocking behaves exactly as rxjava.. now I need to figure out why IDE warns me about Inapropriate blocking call when using it 😀
l
Because it can block, and that might not be what you want. Using
conflate()
or properly configured
buffer(…)
along with
trySend(…)
is often a better solution (but it depends on use case and requirements).
u
why does the method exist then
l
I guess there are use cases for it that I'm not aware of.