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.
When should I be using each?
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.
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
.
The problem with fulfill
existing at all is that deferredPromise.fulfill(rejectedPromise)
is semantically paradoxical.