https://kotlinlang.org logo
Title
z

zjuhasz

02/03/2021, 8:17 AM
Is there a way to check if a
SharedFlow
that is set to
BufferOverflow.DROP_OLDEST
actually drops a value from its buffer due to the buffer being full? I would like to log a warning when this occurs.
t

tateisu

02/03/2021, 9:33 AM
I think there is no API to hook dropping, but you can use tryEmit to avoid suspend until there is a buffer space available.
A shared flow configured with a BufferOverflow strategy other than SUSPEND (either DROP_OLDEST or DROP_LATEST) never suspends on emit, and thus tryEmit to such a shared flow always returns true.