Flow is not supported. You should just return ResponseBody directly in a suspend fun
m
ms
09/02/2021, 12:44 PM
the how can I listen to the stream?
z
Zach Klippenstein (he/him) [MOD]
09/02/2021, 1:11 PM
It’s not a stream then, it’s a single suspending call.
Individual network calls were never conceptually streams even with Rx, it just happened that it was convenient to treat them as streams of a single item in order to integrate with the whole RxJava model.
Suspend functions are a much better way to model network calls because they're much closer to how the call actually works - you invoke the call (send the request), then wait for the response (suspend), and when the response comes back your program can continue with processing it (suspend cal resumes/returns).
Zach Klippenstein (he/him) [MOD]
09/02/2021, 1:13 PM
You can easily convert a suspend function into a Flow if you need to treat it as a stream for other reasons. I believe there’s an
asFlow
extension function on suspend function references, or you can do something like