nextapps-de / flexsearch

Next-Generation full text search library for Browser and Node.js
Apache License 2.0
12.54k stars 492 forks source link

.export(..) returns bool sync but internally runs async... #353

Closed flynx closed 10 months ago

flynx commented 2 years ago

Hi,

It seems that .export(..), at least on the Index, returns true right away but internally runs asynchronously, this is a big issue if one is trying to partition or join the exported data in a custom way, for example it is not possible to collect all the exported data into one object and do something with it...

A basic example:

console.log(pre)
console.log(
    index.export(function(key, value){
        console.log('export')
    }) )
console.log('post')

This prints out:

pre
true
post
export
...
export

It would be nice/logical to be able to await for the export to be done, i.e. for .export(..) to return a promise.

Would also be nice if this promise would account for the handler returning a promise, i.e. resolve when all the returned values are resolved (i.e. via Promise.all(..))

Thanks!

TixieSalander commented 1 year ago

+1, the documentation says import/export functions are async but we can't actually use it in an async context because it's impossible to know when the operations are done. Quite frustrating

Screenshot 2023-01-28 at 23 42 17

thexeos commented 1 year ago

The below PR allows for await on export method, which resolves immediately after the last call to callback was made.