]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/promise/first.js.uncompressed.js
1 define("dojo/promise/first", [
5 ], function(array
, Deferred
, when
){
11 var forEach
= array
.forEach
;
13 return function first(objectOrArray
){
15 // Takes multiple promises and returns a new promise that is fulfilled
16 // when the first of these promises is fulfilled.
18 // Takes multiple promises and returns a new promise that is fulfilled
19 // when the first of these promises is fulfilled. Canceling the returned
20 // promise will *not* cancel any passed promises. The promise will be
21 // fulfilled with the value of the first fulfilled promise.
22 // objectOrArray: Object|Array?
23 // The promises are taken from the array or object values. If no value
24 // is passed, the returned promise is resolved with an undefined value.
25 // returns: dojo/promise/Promise
28 if(objectOrArray
instanceof Array
){
29 array
= objectOrArray
;
30 }else if(objectOrArray
&& typeof objectOrArray
=== "object"){
32 for(var key
in objectOrArray
){
33 if(Object
.hasOwnProperty
.call(objectOrArray
, key
)){
34 array
.push(objectOrArray
[key
]);
39 if(!array
|| !array
.length
){
40 return new Deferred().resolve();
43 var deferred
= new Deferred();
44 forEach(array
, function(valueOrPromise
){
45 when(valueOrPromise
, deferred
.resolve
, deferred
.reject
);
47 return deferred
.promise
; // dojo/promise/Promise