Build 613334stable
Module 451988
2,426 characters · in no known chunkDependencies
Required by (88)
222322071245943079340056478995109261230632388055893067101392107750115036116956117029121686130553133296152567167132173155194981206845214103229683251913266536276208279306280483282098282413304072321191340137353411356645360449376151378135415478416052421773428978432166432779436405453314453903461782463105471107492684505806525788529433540462544576552143559908568004569926573163588224590114599812601255604121655116679492689168712440745317759532763827802867805945812343853390860071860603869362900002911411922016940227983495
Lazily required by (0)none
Requires (1)
Lazily requires (0)none
Source Raw
function(e,t,n){"use strict";n.d(t,{BK:()=>s,Ep:()=>i,IX:()=>a,J_:()=>r,OC:()=>o,bY:()=>l}),n(321073);class i{_ref;start(e,t){let n=!(arguments.length>2)||void 0===arguments[2]||arguments[2];(!this.isStarted()||n)&&(this.stop(),this._ref=window.setTimeout(()=>{this._ref=null,t()},e))}stop(){null!=this._ref&&(clearTimeout(this._ref),this._ref=null)}isStarted(){return null!=this._ref}}class r{_timeout;_delay;_handler;constructor(e,t){this._delay=e,this._handler=t,this._timeout=new i}set(e){return this._delay=e,this}delay(){let e=!(arguments.length>0)||void 0===arguments[0]||arguments[0];this._timeout.start(this._delay,this._handler,e)}cancel(){this._timeout.stop()}isDelayed(){return this._timeout.isStarted()}}class a{_ref;start(e,t){this.stop(),this._ref=window.setInterval(t,e)}stop(){null!=this._ref&&(clearInterval(this._ref),this._ref=null)}isStarted(){return null!=this._ref}}function s(e){return new Promise(t=>{setTimeout(()=>t(),e)})}class l extends Error{name="BatchInvocationManagerResetError"}class o{invoke;options;_promises=new Set;_pending=new Set;_flushHandler;_activeInvocationCount=0;_flushReady=!1;constructor(e,t={}){this.invoke=e,this.options=t,this._flushHandler=new r(this.options.delay??32,()=>{this._flushReady=!0,this._flush()})}queue(e){let t=Array.isArray(e)?e:[e],n=[];for(let e of t)(this.options.predicate?.(e)??!0)&&!this._pending.has(e)&&(this._pending.add(e),n.push(e));return(n.length>0&&this.options.onQueued?.(n),0===this._pending.size)?Promise.resolve():new Promise((e,t)=>{this._promises.add({resolve:e,reject:t}),this._flushReady||this._flushHandler.delay(!1)})}reset(){let e=[...this._pending],t=[...this._promises],n=new l("BatchInvocationManager was reset");this._pending.clear(),this._promises.clear(),this._flushReady=!1,this._flushHandler.cancel(),e.length>0&&this.options.onCancelled?.(e),t.forEach(e=>e.reject(n))}isPending(){return this._pending.size>0}isInvoking(){return this._activeInvocationCount>0}async _flush(){let e=this.options.maxConcurrentInvocations??1/0;if(!this._flushReady||this._activeInvocationCount>=e)return;let t=[...this._pending];this._pending.clear();let n=[...this._promises];if(this._promises.clear(),this._flushReady=!1,0===t.length)return void n.forEach(e=>e.resolve());this._activeInvocationCount+=1;try{await this.invoke(t),n.forEach(e=>e.resolve())}catch(e){n.forEach(t=>t.reject(e))}finally{this._activeInvocationCount-=1,this._flush()}}}}