https://kotlinlang.org logo
#coroutines
Title
# coroutines
p

Paul Woitaschek

07/09/2019, 8:01 AM
When I wrap a single value in a flow: Is there a better way than writing
flow { emit(mySuspendingFunction()) }
?
d

dekans

07/09/2019, 8:38 AM
maybe make your function return a flow. The
collect()
will be suspending anyway
d

Dico

07/09/2019, 9:47 AM
I dont think there is.
flowOf(x)
probably doesn't work in your case.
But you can make a function yourself of course
g

gildor

07/09/2019, 9:55 AM
There is
::mySuspendingFunction.asFlow()
❤️ 1
or (if function requires some arguments), you can just create suspend lambda:
Copy code
suspend { mySuspendingFunction(something) }.asFlow()
the same for non-suspend function
p

Paul Woitaschek

07/09/2019, 2:48 PM
Thanks a lot 🙂
6 Views