GM_pLimit

并发控制

Questo script non dovrebbe essere installato direttamente. È una libreria per altri script da includere con la chiave // @require https://update.greasyfork.org/scripts/565266/1749341/GM_pLimit.js

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

(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;
})();