Closed leandrofavarin closed 1 year ago
Thanks for reporting this, unfortunately I wasn't able to reproduce this. The following seems to work:
struct ClockView: View {
@State var state: KotlinLong = 0
@State var publisher: AnyPublisher<KotlinLong, Never>
private let content: (KotlinLong) -> Text
init() {
publisher = createPublisher(for: Clock().time).assertNoFailure().eraseToAnyPublisher()
content = { Text("\($0)") }
}
var body: some View {
content(state)
.onReceive(publisher) { self.state = $0 }
}
}
Could you possible share a reproducer? Feel free to use the sample project.
I should have added one yesterday, sorry! You can find a repro here. 🙏
No problem! It seems only the following combination results in a thread freeze:
StateFlow
(from the main thread)CoroutineScope
with Dispatchers.Main.immediate
The reason being that there is always an initial value that is immediately send to the Swift callback. Fixed by making sure the Flow collection is started after the lock has been released.
FYI this has been fixed in v1.0.0-ALPHA-17.
I believe there's a regression from https://github.com/rickclephas/KMP-NativeCoroutines/pull/126. In my case I'm creating a Publisher from a SwiftUI View initialiser, like so:
This didn't happen on ALPHA-14.