Flow and Cancellation/onCompletion Callback not working #79
Closed
frankois944
started this conversation in
General
Replies: 1 comment
-
This is the following code I'm using on swiftUI Even I'm forcing the task to cancel, on the kotlin side, class MyMainScreenViewModel: ObservableObject {
let viewmodel: MainScreenViewModel
var jobs = Set<Task<(), Never>>()
@Published
private(set) var mainScreenUIState: MainScreenUIState = .Loading()
init(viewmodel: MainScreenViewModel = MainScreenViewModel(param1: nil)) {
self.viewmodel = viewmodel
jobs.insert(Task { @MainActor [weak self] in
for await data in viewmodel.mainScreenUIState {
self?.mainScreenUIState = data
}
})
}
deinit {
print("DESTROYED \(self)")
jobs.forEach {
print("CANCEL \($0)")
$0.cancel()
}
jobs.removeAll()
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, I'm using Flow on SwiftUI,
On the kotlin side, i'm listening the events
.onStart {}
and.onCompletion {}
of theStateFlow
bound to the view.When the view is destroy, the flow must be cancelled, right?
onStart
is correctly called but notonCompletion
on the SwiftUI.Do I miss someting?
Beta Was this translation helpful? Give feedback.
All reactions