Hello there, if ```repositoryContract.retrieveTopS...
# coroutines
m
Hello there, if
Copy code
repositoryContract.retrieveTopStories()
is a suspend function which returns
List<Story>
why I can’t convert it to Flow by calling
Copy code
repositoryContract.retrieveTopStories().asFlow()
j
What issue are you seeing? I just tried something similar here and it seemed to work
e
Flow is clod. You have to perform the action when collected, so the proper way is to:
Copy code
flow {
    repositoryContract.retrieveTopStories()
        .forEach { emit(it) } 
}
👍 1
j
somewhat contrived but just tried following and that seems to work fine.....though maybe I misunderstood ask
Copy code
fun main()  = runBlocking {
    val api = PeopleInSpaceApi()

    api.fetchPeople().asFlow().collect {
        println(it)
    }
}
c
Could also be missing the kotlinx couroutines library.
g
If you want to convert it to flow which emits whole list, you need method reference: repositoryContract::retrieveTopStories.asFlow()
👍 1