您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
基于promise 并发控制
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/488850/1336774/promise%20concurrency.js
- // ==/UserScript==
- // @version 1.0
- // ==/UserScript==
- ; (() => {
- /**
- * # 使用方法
- * ```js
- * await concurrentTasks(5, [1, 2, 3, 4], (n) => {
- * return new Promise((ok) => {
- * setTimeout(() => {
- * console.log(n);
- * ok();
- * }, Math.random() * 5000);
- * });
- * });
- * ```
- * @template T
- * @param {number} limit - 并发数
- * @param {T[] | NodeListOf<T>} tasks - 可迭代对象
- * @param {(task:T) => Promise<void>} asyncCallback - Promise 回调函数
- * @returns {Promise<void>}
- */
- const concurrentTasks = async (limit, tasks, asyncCallback) => {
- limit = Math.min(limit, tasks.length);
- let index = 0;
- const run = async () => {
- while (index < tasks.length) {
- await asyncCallback(tasks[index++]);
- }
- };
- const runTaks = Array.from({ length: limit }, () => run());
- await Promise.all(runTaks);
- };
- window.concurrentTasks = concurrentTasks;
- })();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址