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

QueryIterator should be a proper iterator #172

Closed
spencerhakim opened this issue Mar 10, 2017 · 3 comments
Closed

QueryIterator should be a proper iterator #172

spencerhakim opened this issue Mar 10, 2017 · 3 comments
Milestone

Comments

@spencerhakim
Copy link

ES2015 provides a standard for implementing iterators in JavaScript, and it's rather misleading that something called QueryIterator doesn't actually support this.

@jcormont
Copy link

A true ES2015 iterator would be impossible to implement, because data is fetched asynchronously (in chunks). The iterator has to return something synchronously from the next() call though, and so it would never be able to set .done until the data is loaded (not synchronously, i.e. not right away so a synchronous for loop would either quit early or loop forever).

However, there is in fact also an upcoming spec for async iterators, where the next() call returns a Promise for the done/value object. At the moment this hasn't really been implemented yet in Node though (we need Symbol.asyncIterator for this to work fully).

The good news is that the next version of TypeScript (2.3) will include a shim for this. See this issue. Once that lands I'll add it to my project documentdb-typescript, and you'll be able to write a loop in TypeScript as if everything was synchronous for await (const myResult of coll.queryDocuments(...)) { ... }.

@christopheranderson
Copy link
Contributor

I like this idea for query.forEach() in the v2 SDK. I was thinking the same thing before seeing this issue.

@christopheranderson christopheranderson added this to the v2 milestone Jun 5, 2018
@southpolesteve
Copy link
Contributor

We have recently announced deprecation version 1.x of the Azure Cosmos JavaScript SDK. We will end support for the documentdb package and this repo on August 30, 2020. Please update to our new package @azure/cosmos as soon as possible. If you encounter any issues, you can raise them in the Azure central JS SDK repo. If something is preventing you from upgrading to the latest version of the SDK, you can always email me directly: stfaul@microsoft.com

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

No branches or pull requests

4 participants