q.js:解决之差()和满足() [英] q.js: difference between resolve() and fulfill()

查看:136
本文介绍了q.js:解决之差()和满足()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍然不清楚的差异调用一个解析器的决心(间)与满足()?我看到这两个功能和术语解决一个承诺和履行承诺周围有很多反复推敲。

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屋!

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