除了同步与异步之外,它们文档中的差异也让我感到困惑。他们的例子github页面 https://github.com/BoltsFramework/Bolts-Android#chaining-tasks-together看起来仍然是同步调用的延续。
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.
当你有返回一个的辅助方法时Task
对象,你不能使用continueWith()
or onSuccess()
因为 Bolts 代码不会将其视为Task
并等待其执行。它将治疗Task
作为一个简单的数据结果。
基本上,这是行不通的,因为该链的最终任务是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>
:
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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)