I’m looking for an alternative to flow.emit(). I w...
# coroutines
I’m looking for an alternative to flow.emit(). I would need of a data structure (a sized circular buffered list) that would be “coroutine-safe” and the “put” operation is not blocking. The producer should not depend on the consumer and, it should be able to emit data even if there are no consumers listening. I was thinking to Channels, but they offers non-suspending send() only when declared Channel.UNLIMITED. Do you have any suggestion?
I'm going to assume by "not blocking" you mean "not suspending" -- how do you expect to accomplish this without a potentially unlimited size buffer?
the only other alternative is to drop items somewhere, otherwise it must suspend to wait for the buffer to have free space
yes, sorry by non-blocking I meant not suspending. Buffer should be limited, old values should be replaced by fresh ones (as a circular buffer)
something similar to
I think you'd probably have to implement this yourself, though you might be able to re-use mechanics from Channel.CONFLATED
Thanks Octavia, I thought something was already out there… 😞
I'm not familiar with any coroutines libraries myself unfortunately, there might be something that I don't know about
personally I haven't yet had the need to go looking
I think your use case is covered by the upcoming
and the
strategy. https://github.com/Kotlin/kotlinx.coroutines/issues/2034
Thanks @Zach Klippenstein (he/him) [MOD]! I think it will handle my use case …