In Bolts, how do you use continueWith () and continueWithTask ()?

Besides syncing with async, the differences in their documentation are confusing to me. The examples on the github page still look like continuations are invoked synchronously.

continueWith() Adds a synchronous continuation to this task, returning a new task that completes after the continuation has finished running.

continueWithTask() Adds an asynchronous continuation to this task, returning a new task that completes after the task returned by the continuation has completed.

+5
source share
1 answer

When you have helper methods that return a Task object, you cannot use continueWith() or onSuccess() because the Bolts code will not treat it as a Task and wait for it to execute. He will consider Task as a simple data result.

In principle, this will not work, because the resulting task of this chain is Task<Task<Void>> :

 update().onSuccess(new Continuation<ParseObject, Task<Void>>() { public Task<Void> then(Task<ParseObject> task) throws Exception { return Task.delay(3000); } }) // this end returns a Task<Task<Void>> 

But this will work, and the chain will return a Task<Void> :

 update().onSuccessTask(new Continuation<ParseObject, Task<Void>>() { public Task<Void> then(Task<ParseObject> task) throws Exception { return Task.delay(3000); } }) // this end returns a Task<Void> 
+3
source

All Articles