Hello there! Is there a way to check if a `Flow&l...
# coroutines
u
Hello there! Is there a way to check if a
Flow<T>
with
debounce(...)
operator applied to it has currently a pending value that will be emitted after debounce delay? I have a specific problem with the following use case on Android. Inside a
ViewModel
, I am using a
Channel<String>
to organize pipeline for sending text changes to some remote backend: this channel is consumed as
Flow<String>
, where on each emission the value is sent (with delay resulting from
debounce()
operator) to the backend. When this
ViewModel
is to be destroyed and
onCleared()
is called, I cancel that same
Channel<String>
. But there is an expected but still unpleasant side-effect, which I need to eliminate: the last value is not guaranteed to be sent if there is a pending emission due to debounce delay, which gets cancelled when
channel.cancel()
is called. Any suggestions will be very appreciated!
b
If you switch to
channel.close()
all events will be processed (assuming collector is working in non-cancelled scope)