mirror of
https://github.com/Doodle3D/Doodle3D-Core.git
synced 2025-01-03 08:33:48 +01:00
use async iterator without regenerators
This commit is contained in:
parent
6fa71c4855
commit
4d46eb6f91
@ -15,11 +15,30 @@ export function recursivePromiseApply(object, promises = [], first = true) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function asyncIterator(array, callback) {
|
export async function asyncIterator(array, callback) {
|
||||||
const result = [];
|
return new Promise((resolve, reject) => {
|
||||||
for (let i = 0; i < array.length; i ++) {
|
const results = [];
|
||||||
const item = array[i];
|
let i = 0;
|
||||||
const itemResult = await callback(item, i, array);
|
|
||||||
result.push(itemResult);
|
function loop() {
|
||||||
}
|
if (i === array.length) return resolve(results);
|
||||||
return result;
|
|
||||||
|
const item = array[i];
|
||||||
|
callback(item, i, array).then(result => {
|
||||||
|
results.push(result);
|
||||||
|
i ++;
|
||||||
|
loop();
|
||||||
|
}).catch(reject);
|
||||||
|
}
|
||||||
|
loop();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// export async function asyncIterator(array, callback) {
|
||||||
|
// const result = [];
|
||||||
|
// for (let i = 0; i < array.length; i ++) {
|
||||||
|
// const item = array[i];
|
||||||
|
// const itemResult = await callback(item, i, array);
|
||||||
|
// result.push(itemResult);
|
||||||
|
// }
|
||||||
|
// return result;
|
||||||
|
// }
|
||||||
|
Loading…
Reference in New Issue
Block a user