Hi! Can someone help me with this? Is there a simp...
# getting-started
g
Hi! Can someone help me with this? Is there a simple method to transform the following
Copy code
responseBody =  myTask.get();
into an async callback?
d
You could try #coroutines, see the callback into coroutines section here https://github.com/Kotlin/kotlin-coroutines/blob/master/kotlin-coroutines-informal.md
Oh, no, I'm not awake yet, you asked making get() into async callback... You should specify where that get is from... It depends... But you could take a look at https://github.com/Kotlin/kotlinx.coroutines/blob/master/coroutines-guide.md, it simplifies working with callbacks tremendously
async{ myTask.get() }
should put it into a CommonPool thread and return a Deferred with the response body, and then you can call await to get it from inside any coroutine (which is like a callback but much more powerful...). You can see the guide for more details
g
Thank you very much gor your response. Sorry I've seen now b/c I didn't get notified I will study your link. Before that, yes the problem is where the get is located in the code. It's inside a method returning an array which in turn is wrapped in a void event handler, more or less. So now it works but gui freezes that's why I'd like to improve but I'm afraid it would impact a lot of code. Actually I think I have to use onPostExecute AsyncTask in this specific case. Thanks again for your replies!!