GM_pLimit

并发控制

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/565266/1749341/GM_pLimit.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

(function () {
  /**
   * yocto-queue
   * https://www.npmjs.com/package/yocto-queue
   */
  class Node{value;next;constructor(value){this.value=value}}class Queue{#head;#tail;#size;constructor(){this.clear()}enqueue(value){const node=new Node(value);if(this.#head){this.#tail.next=node;this.#tail=node}else{this.#head=node;this.#tail=node}this.#size++}dequeue(){const current=this.#head;if(!current){return}this.#head=this.#head.next;this.#size--;if(!this.#head){this.#tail=undefined}return current.value}peek(){if(!this.#head){return}return this.#head.value}clear(){this.#head=undefined;this.#tail=undefined;this.#size=0}get size(){return this.#size}*[Symbol.iterator](){let current=this.#head;while(current){yield current.value;current=current.next}}*drain(){while(this.#head){yield this.dequeue()}}}

  /**
   * p-limit
   * https://www.npmjs.com/package/p-limit
   */
  function pLimit(concurrency){let rejectOnClear=false;if(typeof concurrency==="object"){({concurrency,rejectOnClear=false}=concurrency)}validateConcurrency(concurrency);if(typeof rejectOnClear!=="boolean"){throw new TypeError("Expected `rejectOnClear` to be a boolean");}const queue=new Queue();let activeCount=0;const resumeNext=()=>{if(activeCount<concurrency&&queue.size>0){activeCount++;queue.dequeue().run()}};const next=()=>{activeCount--;resumeNext()};const run=async(function_,resolve,arguments_)=>{const result=(async()=>function_(...arguments_))();resolve(result);try{await result}catch{}next()};const enqueue=(function_,resolve,reject,arguments_)=>{const queueItem={reject};new Promise((internalResolve)=>{queueItem.run=internalResolve;queue.enqueue(queueItem)}).then(run.bind(undefined,function_,resolve,arguments_));if(activeCount<concurrency){resumeNext()}};const generator=(function_,...arguments_)=>new Promise((resolve,reject)=>{enqueue(function_,resolve,reject,arguments_)});Object.defineProperties(generator,{activeCount:{get:()=>activeCount,},pendingCount:{get:()=>queue.size,},clearQueue:{value(){if(!rejectOnClear){queue.clear();return}const abortError=AbortSignal.abort().reason;while(queue.size>0){queue.dequeue().reject(abortError)}},},concurrency:{get:()=>concurrency,set(newConcurrency){validateConcurrency(newConcurrency);concurrency=newConcurrency;queueMicrotask(()=>{while(activeCount<concurrency&&queue.size>0){resumeNext()}})},},map:{async value(iterable,function_){const promises=Array.from(iterable,(value,index)=>this(function_,value,index),);return Promise.all(promises)},},});return generator}function limitFunction(function_,options){const limit=pLimit(options);return(...arguments_)=>limit(()=>function_(...arguments_))}function validateConcurrency(concurrency){if(!((Number.isInteger(concurrency)||concurrency===Number.POSITIVE_INFINITY)&&concurrency>0)){throw new TypeError("Expected `concurrency` to be a number from 1 and up",);}}

  window.GM_pLimit = pLimit;
})();