CoroutineStart.UNDISPATCHED
flaky with collectLatest
#4383
Labels
CoroutineStart.UNDISPATCHED
flaky with collectLatest
#4383
This test due to the flaky code:
The goal is to launch a job and start collecting a flow before the next instructions happen. In the sample it so happens when
tryEmit
is called that there sometimes is a subscriber and sometimes there isn't. This behavior is surprising and unintuitive.I found multiple workarounds to fix that, but ideally the sample would work fine:
collect
instead ofcollectLatest
. With that the test is green, but in my production code I need the behavior ofcollectLatest
.replay = 1
for the shared flow. Then the missed value on the flow would be replayed. But this isn't ideal for more values or if there other subscribers that don't want the replay behavior.Dispatchers.Unconfined
when launching the job. This is a significant change with other side effects.Is this behavior expected? What is the recommendation for this use case?
The text was updated successfully, but these errors were encountered: