export let FinishCallback;export class Throttler{constructor(s){this._timeout=s,this._isRunningProcess=!1,this._asSoonAsPossible=!1,this._process=null,this._lastCompleteTime=0,this._schedulePromise=new Promise((s=>{this._scheduleResolve=s}))}_processCompleted(){this._lastCompleteTime=this._getTime(),this._isRunningProcess=!1,this._process&&this._innerSchedule(!1),this._processCompletedForTests()}_processCompletedForTests(){}_onTimeout(){delete this._processTimeout,this._asSoonAsPossible=!1,this._isRunningProcess=!0,Promise.resolve().then(this._process).catch(console.error.bind(console)).then(this._processCompleted.bind(this)).then(this._scheduleResolve),this._schedulePromise=new Promise((s=>{this._scheduleResolve=s})),this._process=null}schedule(s,e){this._process=s;const i=Boolean(this._processTimeout)||this._isRunningProcess,t=this._getTime()-this._lastCompleteTime>this._timeout,o=(e=Boolean(e)||!i&&t)&&!this._asSoonAsPossible;return this._asSoonAsPossible=this._asSoonAsPossible||e,this._innerSchedule(o),this._schedulePromise}_innerSchedule(s){if(this._isRunningProcess)return;if(this._processTimeout&&!s)return;this._processTimeout&&this._clearTimeout(this._processTimeout);const e=this._asSoonAsPossible?0:this._timeout;this._processTimeout=this._setTimeout(this._onTimeout.bind(this),e)}_clearTimeout(s){clearTimeout(s)}_setTimeout(s,e){return window.setTimeout(s,e)}_getTime(){return window.performance.now()}}