-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IsolateState can not work with coroutines MutableStateFlow: kotlin.native.concurrent.FreezingException: freezing of Ok(result=kotlinx.coroutines.flow.StateFlowImpl@80804878) has failed, first blocker is kotlinx.coroutines.flow.StateFlowImpl@80804878 #71
Comments
This code directly violates the basic concept of flowState
.access { it } The thing that's kept isolated, The exception is happening because when you try to return the As for what you should do instead, I'm not sure. Flows are freezable, generally speaking. The bug you linked is old and fixed. |
@kpgalligan Thanks for your replay. But how to use MutableStateFlow with IsolateState please? |
Use
|
Why are you using private val flowState = MutableStateFlow("1")
@OptIn(ExperimentalCoroutinesApi::class)
@Test
fun test() = runBlockingTest {
println("runBlockingTest start")
val job = launch {
flowState
.asStateFlow()
.collect {
run()
}
}
flowState.value = "123"
// job.cancel()
println("runBlockingTest end")
}
private suspend fun run() {
println("collect:${flowState.value}")
} |
Because the MutableStateFlow instance may be accessed to get or set new value in multi-thread. |
@kpgalligan
|
Yes, until your loop is done. IsolateState isn't async and access isn't a suspend. |
Is there a workaround to handle time-consuming task and don't block main thread? |
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1-native-mt
iosTest sorceset:
got error:
The text was updated successfully, but these errors were encountered: