rethinkdbdash icon indicating copy to clipboard operation
rethinkdbdash copied to clipboard

Add async iterator interface to cursors

Open mxstbr opened this issue 7 years ago • 5 comments

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)

mxstbr avatar Mar 12 '18 11:03 mxstbr

Wercker failed even though all tests passed 🤔

mxstbr avatar Mar 12 '18 12:03 mxstbr

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?

segphault avatar Apr 25 '18 00:04 segphault

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!

mxstbr avatar Apr 25 '18 07:04 mxstbr

@neumino ?

thelinuxlich avatar May 02 '18 17:05 thelinuxlich

merged in https://github.com/RebirthDB/rebirthdb-js

thelinuxlich avatar May 23 '18 14:05 thelinuxlich