Open chriscoomber opened 3 years ago
@chriscoomber thanks a lot for your feedback. Indeed some more flexibility is welcome. Recently we introduced the possibility to use the onResume/onPause callbacks alternatively to onStart/onStop.
I will carefully consider your suggestions and think through how to introduce support for collectLatest in a way that is consistent with the current public API.
I've found that most of the time in UI code you really want
collectLatest
rather thancollect
. If your UI code has gone away rendering a thumbnail or doing a bunch of heavy computations, you need to be able to interrupt that when the latest value of whatever flow you were watching is delivered (which may invalidate that work). Assuming the block of code that you pass tocollectLatest
employs cooperative cancellations (e.g. callingensureActive()
oryield()
relatively often) then this all just works.At the moment this library uses
collect
only.I'm not exactly sure what I'd want the API to look like to support
collectLatest
. I ended up writing the following extension function instead of using your library. The following extension function simply launches and cancels, it's up to you what you want to put inside, whether it becollect
,collectLatest
,combine
or whatever. This constitutes a solution for me, so this issue is by no means urgent, and I guess it's become more of a suggestion...