基于promise 并发控制
This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/488850/1336774/promise%20concurrency.js
await concurrentTasks(5, [1, 2, 3, 4], (n) => {
return new Promise((ok) => {
setTimeout(() => {
console.log(n);
ok();
}, Math.random() * 5000);
});
});