I'm looking at some existing code that uses when.js
. A pattern that appears a few times is:
return when(someBigFunction(), function() {
doSomeMoreProcessing();
if (maybe) {
throw someError;
}
});
I imagine the reason they use when
here is they weren't sure at the time whether someBigFunction()
would be returning a promise or not.
Is there a difference, semantically between the above and:
return when(someBigFunction()).then(function() {
...
});
Generally the examples don't make use of the return value of the promise (that is, it's function() {
not function(x) {
)
.
The API docs offer this:
when(x,f)
: Get a trusted promise by transforming x with fthen
: Transforms a promise's value by applying a function to the promise's fulfillment value.
So I suspect there is no difference, but maybe I'm missing a subtlety?