等待多个延迟对象完成并使用已解析的值

等待多个延迟对象完成并使用已解析的值

本文介绍了等待多个延迟对象完成并使用已解析的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图想办法等待多个延迟对象并在完成后处理它们,可能就像为延迟对象开始下一组。

I am trying to figure out a way to wait for multiple deferred objects and process them once done, may be like to start next set for deferred objects.

I我被困了,因为以下的结果不是预期的结果。
我期待结果为

I am stuck because the result of the following is not the it is expected to be.I am expecting the result as

 c> c>  c> c>  c> c>  c>  c>  c>  c>  c>  c>已解决( c>完成回调之后标记已解决,因此当您的代码运行时, dfd1 和 dfd2 已解决,但 dfd3 仍在解决过程中。因此,对于 dfd1 和 dfd2 同步调用内部回调,但异步  dfd3 。因此,在将 dfd3 返回值推送到数组之前,您将输出结果。

So what's happening in your code is that the overall done callback that when fires is fired during the done callback on the last promise that got resolved (dfd3). Since the promise isn't marked resolved until after the done callbacks have been completed, when your code runs, dfd1 and dfd2 are resolved but dfd3 is still in the process of being resolved. So your inner callbacks are called synchronously for dfd1 and dfd2 but asynchronously for dfd3. So you're outputting your result before the dfd3 return value has been pushed onto your array.

这篇关于等待多个延迟对象完成并使用已解析的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 22:44