Hello all I got an external API which delivers dat...
# coroutines
b
Hello all I got an external API which delivers data via an callback running on a different thread. How could I encapsulate those data into flows? An simple example, given an external API:
fun externalApi(query: String, callback: (Long,String)->Unit): Unit
I would like to convert this into something like
fun externalApiWrapper( query: String ): Flow<Pair<Long,String >>
Currently I have no idea how to do that.
b
Thanks, that works for me. 🙂
g
Just want to check, is this callback called multiple times, so is it stream of events?
b
Yes, the callback will be called multiple times.
But I got one more question, regarding the back pressure. If it happens that the producer would be faster, how could modify specify the behavior of the "hidden" channel object? E.g. how could I block the thread of the producer, when I call the offer method. I did not really get the buffer method (mentioned in the comment of the link you provided).
g
You can change behavior of hidden channel using buffer method, what is exactly not clear? You can just set channel capacity using it
If you want to block the producer's thread, you can wrap send() method with runBlocking
b