GM_pLimit

并发控制

Този скрипт не може да бъде инсталиран директно. Това е библиотека за други скриптове и може да бъде използвана с мета-директива // @require https://update.greasyfork.org/scripts/565266/1749341/GM_pLimit.js

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да инсталирате разширение, като например Tampermonkey .

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като 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;
})();