Closed carlos-mg89 closed 5 years ago
doAysnc
returns a Feature
object, you need to await
it. the doAsync
may start slower than the thread version since it is backed by a ScheduledThreadPool
, your unzip task may have to wait in the task queue for a while.
In the Thread
version, how do you know the unzip operation is complete?
I'm using a BroadcastReceiver
that awaits for a download to be completed. Once it completes, the the BroadcastReceiver.onReceive
method gets an Intent with the information I need to unzip the downloaded file.
So actually this thread is already being called outside the user flow. And in that onReceive call, I simply open a thread (the one I tried to replace by Anko version) where I unzip the file.
But it makes sense now I had to wait for the doAsync to finish. Will test the Anko doAsync version somewhere else in my app, where I want to achieve a multithreaded code, so it runs faster with parallel threads for different tasks.
Thanks for replying back!
Hi,
I'm testing the anko doAsync corroutine to start with this library that seems pretty interesting and clean.
At first glance, it seemed that everything was working alright, but somehow I have bumped into an issue related with a maximum time for the async task that's limiting seriously my code.
This is my code (a call to unzip a file and a method to unzip it):
And this is the code I had before using Anko:
The code before using Anko works perfectly fine. It unzips my zip file and all it's contents. It has been used many many times and it always works fine.
However, when I migrated it to Anko (which I expected it'll work normally), now my zip files are only partly unzipped. Some of the files aren't being extracted. And it ONLY happens while using the
doAsync
instead of the runnable thread.To be honest, I would prefer using Anko. It has proved to be cleaner and simpler, and way easier to remember than the current setup. Perhaps there is any limitations with the kind of task it can be done? Or there is a maximum time for the async task to be done?
Thanks in advance