Add async iterator interface to cursors#371
Conversation
|
Wercker failed even though all tests passed 🤔 |
| (error.message.match(/You cannot call `next` on a closed/) === null)) { | ||
| return iter.throw(error); | ||
| } else { | ||
| return iter.return(); |
There was a problem hiding this comment.
@mxstbr What other errors might occur? why stop the iterations for only the above errors?
There was a problem hiding this comment.
Good question, I copied that from the other places where self._next() is called. Not sure why it's that specific, honestly!
There was a problem hiding this comment.
I suppose it makes sense, since any other errors you might want to ignore where as these don't make sense to continue.
This does raise a question though. With callbacks you get the error and can ignore or handle it.
In this case you wont get it. maybe it should be a part of the return iter.return(err).
This also makes me really wonder what errors are possible... I'll ask around.
|
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 |
Already possible! |
|
@neumino ? |
See #370, this patch adds a
cursor.asyncIteratormethod which returns an async iterator:I added
iterallas a dependency since I need to use it in the tests anyway, but if you want me to I can move it to thedevDependenciesand inline the$$asyncIteratorpolyfill snippet. (it's like 3 lines)