I'm having issues consuming a refreshable flow fro...
# multiplatform
m
I'm having issues consuming a refreshable flow from iOS. I have the flow working as expected when subscribing to it, but when trying to call the
refresh
method to trigger a refresh the flow never emits from the top of the flow: • The next code does not behave the same between Android and iOS • When calling
refresh()
from both apps: ◦ Android: ▪︎ Prints the
"Emit refresh"
and the
"1 refreshing flow!"
and
"2 remitting flow!"
, showcasing that the flow chain is retriggered as expected. ◦ iOS: ▪︎ Only prints the first
"Emit refresh"
and nothing else happens after.
Copy code
private val refreshTrigger: MutableSharedFlow<Unit> = MutableSharedFlow<Unit>(extraBufferCapacity = 1)

    override operator fun invoke() = refreshTrigger
        .onStart { emit(Unit) }
        .onEach { Logger.i("1 refreshing flow!") }
        .flatMapLatest {
            ReveriLogger.i("2 remitting flow!")
            randomFlow()
        }
        .asResult()

    override fun refresh() {
        ReveriLogger.i("Emit refresh")
        refreshTrigger.tryEmit(Unit)
    }
If the
randomFlow()
reemits, everything works on iOS. So we are correctly listening to the flow. It seems the issue is only with the refresh not working 🤔
1
We are using skie so the flows are converted to AsyncSequence
v
So I just tried your code. Launched it on Android and iOS. It does work the same when everything's running on Kotlin. Now I'm not sure what that
asResult()
function is doing and what it is returning, that might have some issue. Also not sure what exactly
randomFlow
does, it might be the issue.
Eh, maybe better like this. https://pastebin.com/HVsvQQcy (Did not know that snippet files are not shown in here)
m
We just found the issue! Essentially we were returning a @Factory with Koin, what resulted in two different objects being created in memory on the iOS side, and when calling refresh we were calling the incorrect object and not the one that we were subscribed to 😅 So it appears we have figured out the mystery here! Thank you for trying it @Vidmantas Kerbelis 🙏
🙌 2