-
Notifications
You must be signed in to change notification settings - Fork 67
SWIFT-718 Add a toArray method to async cursor and change stream #406
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
Conversation
Sources/MongoSwift/MongoCursor.swift
Outdated
| */ | ||
| internal func all() -> EventLoopFuture<[T]> { | ||
| public func toArray() -> EventLoopFuture<[T]> { | ||
| guard self.isAlive else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without this, we would never error even if you call this on a closed cursor and would always return an empty array, because self.cached.clear() would just return nil if the cursor is closed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. One thing to note is that calls to isAlive and cached.clear should probably both only occur while the cursor lock is held, which is making me think we may have to move the cache logic into the internal cursor after all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved the caching logic into the common cursor type, and added a static property on MongocCursorWrapper as we discussed to indicate whether we need to cache the first document or not
| // iterating a dead cursor should error | ||
| expect(try cursor.next().wait()).to(throwError()) | ||
|
|
||
| // iterating after calling all should error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was moved down into the toArray test below
patrickfreed
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
This adds
toArrayto asyncMongoCursorand asyncChangeStream.