rethinkdbdash
rethinkdbdash copied to clipboard
Add async iterator interface to cursors
See #370, this patch adds a cursor.asyncIterator method which returns an async iterator:
const feed = yield r.db().table().changes().run();
const iterator = feed.asyncIterator();
for await (var change of iterator) {
console.log(change);
}
console.log('Done!');
I added iterall as a dependency since I need to use it in the tests anyway, but if you want me to I can move it to the devDependencies and inline the $$asyncIterator polyfill snippet. (it's like 3 lines)
Wercker failed even though all tests passed 🤔
I came here to do this and was pleasantly surprised to find a PR already open. Now that async iterators are supported natively in node, this would definitely be nice to have, ideally without polyfill. Would it be possible to use the [Symbol.asyncIterator] protocol so that it's possible to pass the cursor itself directly into the for-await-of loop?
Would it be possible to use the
[Symbol.asyncIterator]protocol so that it's possible to pass the cursor itself directly into the for-await-of loop?
Already possible!
@neumino ?
merged in https://github.com/RebirthDB/rebirthdb-js