Skip to content

Conversation

@kmahar
Copy link
Contributor

@kmahar kmahar commented Feb 19, 2020

Adds forEach to both types and does some internal refactoring, will explain in inline comments

* Calls the provided closure with each event in the change stream as it arrives.
*
* - Returns:
* An `EventLoopFuture<Void>` which will succeed once the change stream is killed via `kill`.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feels like a weird way to put this as at first read it seems unrelated to what this method does, but I'm not sure how else to say this, any ideas?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change stream can be closed via "invalidate" events too (docs). Might be better to just say "... which will resolve/complete once the change stream is closed."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

*/
public var isAlive: Bool {
return self.asyncChangeStream.isAlive
public func isAlive() throws -> Bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this throws now, but the only case I can think of that it would throw in is if you closed the client and then called this method.
which is actually true for basically all our methods but we don't document that anywhere else, so I wasn't sure if it was worth mentioning.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about just catching the error and returning false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very good point. updated both this and the cursor isAlive method to do that

@kmahar kmahar requested a review from patrickfreed February 19, 2020 19:37
Copy link
Contributor

@patrickfreed patrickfreed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a couple comments on docs, the code looks good

* Calls the provided closure with each event in the change stream as it arrives.
*
* - Returns:
* An `EventLoopFuture<Void>` which will succeed once the change stream is killed via `kill`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change stream can be closed via "invalidate" events too (docs). Might be better to just say "... which will resolve/complete once the change stream is closed."

*/
public var isAlive: Bool {
return self.asyncChangeStream.isAlive
public func isAlive() throws -> Bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about just catching the error and returning false?

@kmahar kmahar force-pushed the SWIFT-719/cursor-forEach branch from 3aafc01 to f2d51fc Compare February 21, 2020 17:52

/// The ID used by the server to track the cursor over time. If all of the cursor's results were returnable in a
/// batch, or if the cursor contained no results, this value will be nil.
public let id: Int64?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as we discussed yesterday, this is now retrieved initially and stored rather than computing it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One little nit: maybe say "a single batch", or "the first batch"? Seems just a tad clearer to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woops, I meant to say that, this phrasing is definitely weird. fixed

Copy link
Contributor

@patrickfreed patrickfreed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one tiny nit otherwise lgtm!


/// The ID used by the server to track the cursor over time. If all of the cursor's results were returnable in a
/// batch, or if the cursor contained no results, this value will be nil.
public let id: Int64?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One little nit: maybe say "a single batch", or "the first batch"? Seems just a tad clearer to me.

@kmahar kmahar merged commit 7ccd7ac into master Feb 21, 2020
@kmahar kmahar deleted the SWIFT-719/cursor-forEach branch February 21, 2020 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants