在Bolts中,您如何使用continueWith()和continueWithTask()? [英] In Bolts, how do you use continueWith() vs continueWithTask()?

查看:119
本文介绍了在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>

这篇关于在Bolts中,您如何使用continueWith()和continueWithTask()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆