mirror of
https://github.com/Heretek-AI/GDevelop.git
synced 2026-07-22 10:05:37 -04:00
58ba2668c2
Only show in developer changelog
25 lines
548 B
JavaScript
25 lines
548 B
JavaScript
const makeSimplePromisePool = async function (functions, n) {
|
|
return new Promise((resolve) => {
|
|
let inProgress = 0,
|
|
index = 0;
|
|
function helper() {
|
|
// base case
|
|
if (index >= functions.length) {
|
|
if (inProgress === 0) resolve();
|
|
return;
|
|
}
|
|
|
|
while (inProgress < n && index < functions.length) {
|
|
inProgress++;
|
|
functions[index++]().then(() => {
|
|
inProgress--;
|
|
helper();
|
|
});
|
|
}
|
|
}
|
|
helper();
|
|
});
|
|
};
|
|
|
|
module.exports = { makeSimplePromisePool };
|