-
Notifications
You must be signed in to change notification settings - Fork 107
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
Implement Symbol.asyncIterator for cursors #616
Conversation
317a86f
to
0f5f502
Compare
Hey, @pluma. This is a really cool addition because I've found myself really wanting Example:
Output
That's most likely not what the user wants. And if instead you move it to a different function like so:
Output
It doesn't wait through the loop :( What I've found most useful is processing the cursor batch by batch and awaiting on that. Something like this:
It would be really awesome if that process function could be built into ArrayCursor somehow (possibly forEach?) |
I don't see how doing it batchwise rather than item by item solves the problem of the cursor going away if you're too slow. Is the idea that this might help with situations where items in the same batch could be processed in parallel? |
I could imagine having something like |
@JonDum I've implemented a |
Here's how your async function forOfTest() {
const cursor = await db.query("FOR i IN 1..10000 RETURN i");
for await (const batch of cursor.batches) {
await Promise.all(
batch.map(async (value) => {
const thing = await getSomething(value);
await doSomething(value, thing);
})
);
}
console.log("done");
} |
@pluma Holy moly! That's awesome! I think this will give devs a lot more power to iterate through large collections without running oom! Excited to see this drop in v7 |
The PR has been merged into the v7 branch: https://arangodb.github.io/arangojs/devel/classes/_cursor_.batchedarraycursor.html |
* Implement Symbol.asyncIterator * Add to CHANGELOG, add warning
Not sure if this breaks compat with older node versions.