import Document from"./document.js";import Index from"./index.js";import WorkerIndex from"./worker.js";export default function(a){register.call(a,"add"),register.call(a,"append"),register.call(a,"search"),register.call(a,"update"),register.call(a,"remove"),register.call(a,"searchCache")}let timer,timestamp,cycle;function tick(){timer=cycle=0}function register(a){this[a+"Async"]=function(){const b=arguments,c=b[b.length-1];let d;if("function"==typeof c&&(d=c,delete b[b.length-1]),!timer)timer=setTimeout(tick,0),timestamp=Date.now();else if(!cycle){const a=Date.now(),b=a-timestamp,c=3*(this.priority*this.priority);cycle=b>=c}if(cycle){const c=this;return new Promise(d=>{setTimeout(function(){d(c[a+"Async"].apply(c,b))},0)})}const e=this[a].apply(this,b),f=e.then?e:new Promise(a=>a(e));return d&&f.then(d),f}}