在Bolts中,您如何使用continueWith()和continueWithTask()?
除了同步还是异步之外,它们的文档差异令我感到困惑.他们的 github页面上的示例仍然看起来像是在连续调用同步
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.
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.
continueWithTask()
Adds an asynchronous continuation to this task, returning a new task that completes after the task returned by the continuation has completed.
当您具有返回Task
对象的辅助方法时,您将无法使用continueWith()
或onSuccess()
,因为Bolts代码不会将其视为Task
并等待其执行.它将Task
视为简单数据结果.
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.
基本上,这是行不通的,因为此链的最终任务是Task<Task<Void>>
:
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>>
但这将起作用,并且链将返回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>