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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

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