q.js:解决之差()和满足() [英] q.js: difference between resolve() and fulfill()
问题描述
我仍然不清楚的差异调用一个解析器的决心(间)与满足()?我看到这两个功能和术语解决一个承诺和履行承诺周围有很多反复推敲。
I'm still unclear on the difference between calling a resolver's resolve() vs fulfill()? I see both the functions and the terms "resolve a promise" and "fulfill a promise" batted around a lot.
当我应该使用每个?
推荐答案
解析。 deferredPromise.resolve(nextPromise)
意味着什么等待 deferredPromise
现在将等待 nextPromise
。如果 nextPromise
不是一个承诺可言,它就会变成一个履行承诺而那张告知任何等待它的价值已经变得可用。
You should use resolve
. deferredPromise.resolve(nextPromise)
means that anything waiting for deferredPromise
will now wait for nextPromise
. If nextPromise
is not a promise at all, it gets turned into a fulfilled promise which goes on to inform anything waiting for it that the value has become available.
的完成
方法是一个坏主意,这将是德precated并最终完全消失。 完成
是语义上等同于解析
中的所有有用的情况。它的存在,唯一的原因就是 deferredPromise.fulfill(值)
是人类间preT比 deferredPromise.resolve(值)更容易
,因为解析
超载同时处理 nextPromise
和 finalValue
。
The fulfill
method is a bad idea that will be deprecated and eventually go away entirely. fulfill
is semantically equivalent to resolve
in all useful cases. It’s only reason to exist is that deferredPromise.fulfill(value)
is easier for humans to interpret than deferredPromise.resolve(value)
, since resolve
is overloaded to handle both nextPromise
and finalValue
.
与问题履行
现有的所有是 deferredPromise.fulfill(rejectedPromise)
在语义上自相矛盾。
The problem with fulfill
existing at all is that deferredPromise.fulfill(rejectedPromise)
is semantically paradoxical.
这篇关于q.js:解决之差()和满足()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!