how to join non promises?
baslr opened this issue · comments
Manuel B. commented
Hi,
sometimes I need thomething like this:
mydbcall()
.then (result) ->
return otherdbcall(result.valueA).join(result.valueB)
.spread(dbCallResult, valueB) ->
...
Or is there a other nice way to have valueB without assign it one scope up?
Something like .joinValue()
or so.
Manuel B. commented
in Promise.prototype.join
if(!isArray(j)) j = [j];
for(var i=0; i < j.length; i++) {
if( ! Promise.thenable(j[i]) ) {
j[i] = new Promise().resolve(j[i]);
}
}
could solve it?
Anders Elo commented
sorry for the late reply, github doesn't notify me, need to check why.
Yes, join was meant for promises only, simple to fix though as you say.
Anders Elo commented
you can also return two values by doing:
promise.resolve(something).then(function(valueA){
return [valueA,valueB];
});