3

How can we currently collect Flow from swift?

With the new Support for Kotlin’s suspending functions in Swift flow's collect method gets this rather unwieldy signature in swift

vm.topStoriesFlow.collect(
 collector: Kotlinx_coroutines_coreFlowCollector,
 completionHandler: @escaping (KotlinUnit?, Error?) -> Void
)

Any idea how it might be used or even if its usage is currently supported?

1
  • 2
    This is an opinion and not an answer. The support for suspend functions is kind of odd. You can't really control the dispatcher or lifecycle. In general, I'd still write a wrapper for general suspend functions rather than use the built-in, and even more so for Flow, you'd want to write something specific to what you're doing. dev.to/touchlab/kotlin-1-4-suspend-functions-209 In simpler cases, I think the suspend function output makes sense, but in "real app" scenarios, I think you'd want more control. Commented Sep 4, 2020 at 21:31

1 Answer 1

6

As Kevin stated one possible and popular approach would be to create a wrapper. You can check out kotlinconf-app/CFlow for more info.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.