1
0
mirror of https://github.com/nextapps-de/flexsearch.git synced 2025-09-25 04:51:29 +02:00
Files
flexsearch/dist/module-min/async.js
Thomas Wilkerling 2431b51a4f update index.d.ts
2025-05-08 22:08:07 +02:00

1 line
817 B
JavaScript

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}}