Skip to content

Commit fdb4b07

Browse files
committed
improve implementation of getPromiseResults
1 parent bd005d8 commit fdb4b07

File tree

2 files changed

+28
-32
lines changed

2 files changed

+28
-32
lines changed

glutil.js

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -168,25 +168,21 @@ var GLUtil={
168168
return Promise.resolve({
169169
successes:[], failures:[]});
170170
}
171-
return new Promise(function(resolve, reject){
172-
var ret={successes:[], failures:[]};
173-
var totalPromises=promises.length;
174-
var count=0;
175-
for(var i=0;i<totalPromises;i++){
176-
var promise=promises[i];
177-
promise.then(function(result){
171+
var ret={successes:[], failures:[]};
172+
var retPromise=Promise.resolve(ret);
173+
for(var i=0;i<totalPromises;i++){
174+
var currPromise=promises[i];
175+
retPromise=currPromise.then(function(result){
178176
ret.successes.push(result);
179-
if(progressResolve)progressResolve(result);
180-
count++;
181-
if(count==totalPromises){ resolve(ret); }
182-
}, function(result){
177+
if(progressResolve)progressResolve(result);
178+
return Promise.resolve(ret);
179+
},function(result){
183180
ret.failures.push(result);
184181
if(progressReject)progressReject(result);
185-
count++;
186-
if(count==totalPromises){ resolve(ret); }
187-
});
188-
}
189-
});
182+
return Promise.resolve(ret);
183+
});
184+
}
185+
return retPromise;
190186
},
191187
/**
192188
* Loads a file from a URL asynchronously, using XMLHttpRequest.
@@ -2000,9 +1996,9 @@ Shape.prototype.setTransform=function(transform){
20001996
}
20011997
/**
20021998
* Sets the scale of this shape relative to its original
2003-
* size. See {@link glutil.Transform.setScale}
1999+
* size. See {@link glutil.Transform#setScale}
20042000
* @param {number|Array<number>} x Scaling factor for this object's width,
2005-
* or a 3-element scaling array, as specified in {@link glutil.Transform.setScale}.
2001+
* or a 3-element scaling array, as specified in {@link glutil.Transform#setScale}.
20062002
* @param {number} y Scaling factor for this object's height.
20072003
* @param {number} z Scaling factor for this object's depth.
20082004
* @return {glutil.Scene3D} This object.
@@ -2013,9 +2009,9 @@ Shape.prototype.setScale=function(x,y,z){
20132009
}
20142010
/**
20152011
* Sets the relative position of this shape from its original
2016-
* position. See {@link glutil.Transform.setPosition}
2012+
* position. See {@link glutil.Transform#setPosition}
20172013
* @param {number|Array<number>} x X coordinate
2018-
* or a 3-element position array, as specified in {@link glutil.Transform.setScale}.
2014+
* or a 3-element position array, as specified in {@link glutil.Transform#setScale}.
20192015
* @param {number} y Y-coordinate.
20202016
* @param {number} z Z-coordinate.
20212017
* @return {glutil.Scene3D} This object.
@@ -2026,7 +2022,7 @@ Shape.prototype.setPosition=function(x,y,z){
20262022
}
20272023
/**
20282024
* Sets this object's orientation in the form of a [quaternion]{@link glmath.GLMath}.
2029-
* See {@link glutil.Transform.setQuaternion}.
2025+
* See {@link glutil.Transform#setQuaternion}.
20302026
* @param {Array<number>} quat A four-element array describing the rotation.
20312027
* @return {glutil.Shape} This object.
20322028
*/
@@ -2036,7 +2032,7 @@ Shape.prototype.setQuaternion=function(quat){
20362032
}
20372033
/**
20382034
* Gets the transformation matrix used by this shape.
2039-
* See {@link glutil.Transform.getMatrix}.
2035+
* See {@link glutil.Transform#getMatrix}.
20402036
* @return {Array<number>} The current transformation matrix.
20412037
*/
20422038
Shape.prototype.getMatrix=function(){

0 commit comments

Comments
 (0)