kaerus-component / uP

micro promise

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to join non promises?

baslr opened this issue · comments

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.

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?

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.

you can also return two values by doing:

promise.resolve(something).then(function(valueA){
     return [valueA,valueB];
});