import Document from"./document.js";import Index from"./index.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")}let timer,timestamp;const current={},limit={};function tick(a){timer=0,current[a]=limit[a]}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,a),timestamp=Date.now()),limit[a]||(limit[a]=current[a]=1000),! --current[a]){const c=Date.now(),d=c-timestamp,e=3*(this.priority*this.priority);current[a]=limit[a]=0|limit[a]*e/d||1,timer=clearTimeout(timer);const f=this;return new Promise(c=>{setTimeout(function(){c(f[a+"Async"].apply(f,b))},0)})}const e=this[a].apply(this,b),f=e.then?e:new Promise(a=>a(e));return d&&f.then(d),f}}