Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Besides sync vs async, the differences in their documentation is confusing to me. The examples on their github page still look like the continuations are being called 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.

like image 781
Jeff Engebretsen Avatar asked Jul 30 '15 22:07

Jeff Engebretsen


1 Answers

When you have helper methods that return a Task object, you cannot use continueWith() or onSuccess() because the Bolts code won't treat it as a Task and wait for its execution. It would treat the Task as a simple data result.

Basically, this won't work, because the resulting task of this chain is a 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>
like image 123
Byte Welder Avatar answered Oct 14 '22 02:10

Byte Welder