Download utils/promise-concurrent.js from aseli/quote-api: direct link, hf CLI and curl.
- Browser
- Download file 617 Bytes
-
https://huggingface.co/spaces/aseli/quote-api/resolve/main/utils/promise-concurrent.js
- Command line
-
hf download hf://spaces/aseli/quote-api/utils/promise-concurrent.js
-
curl -L -o promise-concurrent.js https://huggingface.co/spaces/aseli/quote-api/resolve/main/utils/promise-concurrent.js
617 Bytes
| function promiseAllStepN (n, list) { | |
| let tail = list.splice(n) | |
| let head = list | |
| let resolved = [] | |
| let processed = 0 | |
| return new Promise(resolve => { | |
| head.forEach(x => { | |
| let res = x() | |
| resolved.push(res) | |
| res.then(y => { | |
| runNext() | |
| return y | |
| }) | |
| }) | |
| function runNext () { | |
| if (processed == tail.length) { | |
| resolve(Promise.all(resolved)) | |
| } else { | |
| resolved.push(tail[processed]().then(x => { | |
| runNext() | |
| return x | |
| })) | |
| processed++ | |
| } | |
| } | |
| }) | |
| } | |
| module.exports = n => list => promiseAllStepN(n, list) | |