I have code that basicaly looks like this: ```some...
# coroutines
p
I have code that basicaly looks like this:
Copy code
someFlow.collect {
  Log.d(TAG, ">")
  // Some stuff
  Log.d(TAG, "<")
}
So, I should in Android's logcat alternating arrows going left and right. And in most cases, I do. But on some rare occasions, I see 2 going right and 2 going left. Any idea why that might happen?!
m
two possible answers that i can think of. First, ‘some stuff’ is cancellable, and you have some ‘latest’ operator above in the chain. Or second, the logcat is not reliable and messes the order sometimes.
p
Hmm, ther is actualy
conflate
above the
collect
. But, it shouldn't cause the cancelation, no?
And even if id did, Then should just see the first arrow, and not the last, right? But I always see the correct number of pairs, but just the ordering is wrong.
m
yes, it may be possible logcagt messes up the order
just add the timestamp before the arrow
then confirm even out of order the stamp is ordered
p
Good idea with those timestamps! Gonna try it. But I'm afraid logging is correc, because when this "glitch" happens, I see actual error in displayed data in my app.
Yup, the manual timestamps in logs are oredered correctly.
b
try to verify these logs come from the same coroutine:
Copy code
someFlow.collect {
  val identity = Random.nextInt()
  Log.d(TAG, "> $identity")
  // Some stuff
  Log.d(TAG, "< $identity")
}
1
y
Maybe helpful to have a second one outside the collect call, to show they are from the same flow you are collecting from.
b
yes, as Yuri said, this one will show you the full picture:
Copy code
val identity = Random.nextInt()
someFlow.collectIndexed { index, value ->
  Log.d(TAG, "> $identity => $index")
  // Some stuff
  Log.d(TAG, "< $identity => $index")
}
👍🏻 1