https://kotlinlang.org logo
#coroutines
Title
# coroutines
r

rocketraman

01/20/2023, 3:28 PM
Using 1.7.21 and the new native memory model with coroutines 1.6.4. On iOS I have a flow which contains a delay in
transformLatest
, but for some reason the
collect
is essentially running continuously in some kind of tight loop. On Android the same code works fine. Same code also worked fine with native-mt and the older memory model.
solved 1
Looks like the upstream flow is producing values continuously, causing the
transformLatest
to be cancelled -- seems to be an issue with a StateFlow conflation / state equality not working the same as on Android, for some reason.
A change in flow state is causing a call to a remote service, which updates the state, which appears to triggers a new value, and so the flow ends up in a tight loop. I believe the equality operation for that remote state is different on iOS than on Android, which causes the conflation to "fail" on iOS. Doesn't look like a coroutines problem at all.
Yep, its a classic FP comparison issue
A
kotlin.Double
0
on iOS seems to not be comparable with
0
(it prints as
2.89...E-311
) -- weird because I thought 0 was always represented as 0 according to the IEEE FP rules.
e

ephemient

01/22/2023, 6:12 PM
you have probably misidentified the issue
2.89...E-311 is very far from 0.0: it's about
6e12 * Double.MIN_VALUE
r

rocketraman

01/26/2023, 3:45 PM
@ephemient Did you miss the "e-311" scientific notation?
e

ephemient

01/26/2023, 5:26 PM
No.
Double.MIN_VALUE
is about 4.9E-324, which is a lot smaller that your value.
r

rocketraman

01/26/2023, 6:30 PM
Ok. It's still a damn small value. Theories of why there would be such a representation of 0 on iOS are welcome. The 0 value comes from an Apollo graphql API call.
By the way I only care about precision to about 5 decimal places in this particular case, so modifying
equals
in the value container class to do
double
comparison with an appropriate epsilon solved the problem. Still don't know why this was only an issue on iOS though.
2 Views