-
-
Notifications
You must be signed in to change notification settings - Fork 493
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
Feature Request: Revise index.export() to return an Array of Promises #274
Comments
If I had this, I could do something like: const bits = await Promise.all(index.export)
await fs.writeFile(bits, JSON.stringify(bits)) |
function exportIndex(flexSearchIndex) {
// https://github.com/nextapps-de/flexsearch/issues/299
// https://github.com/nextapps-de/flexsearch/issues/274
return new Promise((res, rej) => {
let pkg = [];
const expected = new Set([
"reg",
"reg.cfg",
"reg.cfg.map",
"reg.cfg.map.ctx"
]);
const received = new Set();
const setsEq = (a, b) => {
if (a.size != b.size) {
return false;
}
return Array.from(a).every(el => b.has(el));
};
flexSearchIndex.export((key, data) => {
// https://github.com/nextapps-de/flexsearch/issues/290
// https://github.com/nextapps-de/flexsearch/issues/273
pkg.push([
key
.toString()
.split(".")
.pop(),
data
]);
received.add(key);
if (setsEq(expected, received)) {
res(JSON.stringify(pkg));
}
});
});
} |
I don't need you to do anything. I just want to know how to deal with the data exported. |
If you return a promise, you limit the grammar. It's very painful for people who don't need grammar candy. How should we handle the exported and imported data. I found that there is still undefined content. Why can't we use nodejs streaming? |
We're working on a solution internally at my company. Someone will pull request when it makes it on the top of the to-do stack. In the short term this worked for me. What do you mean by grammar? Ideally the function would return a promise but also support callback style (well, without it being called for each key separately). |
@rpsirois thanks for sharing the function for exporting an index, it is very useful. I just wanted to double check if you intended to release it under the same license (Apache 2.0) as flexsearch? |
There's no license it's just some random code posted on the internet. If we do a pull request it will fall under the FlexSearch license since the code will be incorporated into their project. |
I don't think that What doesn't make sense is that What's needed is that So you can simply write: await index.export(); By the way, the Typescript definitions incorrectly (for the actual code) type |
This is now fixed in v0.7.23 |
This is great news! I don't see a v0.7.23 tag or npmjs.com release. What's the recommended way to pull and benefit from the latest stable code? |
@ts-thomas Thanks for all your hard work on this! |
I see 0.7.3 and 0.7.31 now. Perfect timing as I'm in this code today. Very much appreciated! |
Currently
index.export( function(key, data) {..} )
, returns a single value - the booleantrue
.reg
,cfg
,map
andctx
.Requested Improvement
-Adjust
index.export()
to return an array of promises - i.e., one promise for each prospective callback invocation. [Alternately, return an iterable suitable for aPromise.All()
construct.]Benefits
Example
Simulate an exception in the callback function.
The current export() facility, requires clients to anticipate and track the number of callback invocations AND deal with any exceptions that arise. The proposed facility simplifies these tasks.
The text was updated successfully, but these errors were encountered: