在Bolts中,你如何使用continueWith()vs continueWithTask()?

时间:2015-07-30 22:45:22

标签: android bolts-framework

除了sync和async之外,他们的文档中的差异让我感到困惑。他们的github page上的例子看起来仍然是同步调用的延续。

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.

1 个答案:

答案 0 :(得分:5)

如果您有帮助方法返回continueWith()个对象,则无法使用onSuccess()Task,因为Bolts代码不会将其视为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>

**//.h**

@interface ShipClass : SKSpriteNode 
{
    //extra cool stuff here 
}

- (instancetype)initWithImageNamed:(NSString *)name

@end