Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
flynx opened this issue Nov 5, 2022 · 2 comments · Fixed by #374
Closed

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

flynx opened this issue Nov 5, 2022 · 2 comments · Fixed by #374

Comments

@flynx
Copy link

flynx commented Nov 5, 2022

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
Copy link

+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 added a commit to thexeos/flexsearch that referenced this issue Feb 8, 2023
Create new variable in document and index exports, which contains a handle for Promise resolve call. When Index is exported directly, then `field` argument is `undefined`, thus the Promise is resolved inside the index export method. When Document is exported, then `field` argument is set, thus preventing Promise to be resolved inside Index export method before all indexes, store, and tags are exported.
@thexeos
Copy link
Contributor

thexeos commented Feb 8, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants