I have an AsyncTask . Inside doInBackground() is meteor.call this is a function from the DDP library. Meteor has ResultListener and is asynchronous.
How can I wait for her work and then continue with AsyncTask ?
I have an AsyncTask . Inside doInBackground() is meteor.call this is a function from the DDP library. Meteor has ResultListener and is asynchronous.
How can I wait for her work and then continue with AsyncTask ?
Use the CountDownLatch object.
Create an object before launching the second stream final CountDownLatch cdl = new CountDownLatch(1);
After starting a new thread, do cdl.await();
In the new thread on completion, do cdl.countDown();
You need to break the work in AsIncTask doInBackground () into two parts - before the call to Meteor and after, each of them should be made into a separate AsyncTask. Then you will have three asynchronous tasks that need to be performed sequentially; this is already a clear construction: from the first task callback, you start the second one, and so on.
You can remake using RxJava and RetroLambda like this:
Observable.<String>create(subscriber->{ //выполнится вне UI потока //делаем что-то долгое и тяжёлое (аналог первой части асинк-таска до вызова метода с колбэком) Thread.sleep(5000); //Запускаем асинхронную задачу someVar.someMethodWithCallback(new CallbackListener(){ @Override public void onSuccess(Result result){ //тут делаем какую-то ещё долгую задачу //т.e. действие после асинхронной промежуточной задачи Thread.sleep(5000); //и наконец возвращаем результат subscriber.onNext("some result"); subscriber.onCompleted(); } @Override public void onError(Throwable error) { subscriber.onError(error); } }); }) .subscribe( result->System::out, error->System::out ); Source: https://ru.stackoverflow.com/questions/612383/
All Articles