Skip to content
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

Allow to finish() GRPCAsyncRequestStreamWriter sync, non-throwing #1504

Merged
merged 4 commits into from
Oct 19, 2022

Conversation

schwmi
Copy link
Contributor

@schwmi schwmi commented Oct 14, 2022

Implements #1503

The current implementation of finish() works sync+non-throwing. Therefore the annotations async throws are superfluous. To keep the API stable this PR adds an additional sync, non-throwing finish() method.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 14, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

@Lukasa Lukasa added the 🆕 semver/minor Adds new public API. label Oct 17, 2022
@@ -90,6 +90,11 @@ public struct GRPCAsyncRequestStreamWriter<Request: Sendable>: Sendable {
self.asyncWriter.finish()
}

/// Sync variant for finishing the request stream for the RPC. This must be called when there are no more requests to be sent.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The CI is emitting a bunch of failures because these calls now appear to be ambiguous (which is a little surprising):

/__w/grpc-swift/grpc-swift/Sources/GRPC/AsyncAwaitSupport/GRPCClient+AsyncAwaitSupport.swift:424:11: error: expression is 'async' but is not marked with 'await'
          call.requestStream.finish()
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~
          await 

Could you try marking the async throwing version as @available(*, deprecated)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, this makes sense: I'm not surprised here. The compiler will prefer the async one in async contexts. I think the correct fix is @disfavoredOverload, though I don't know if it can override the preference for the async method.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I suppose that makes sense. I was also wondering about @disfavoredOverload but was hoping deprecating the async variant may implicitly disfavour it (and there's no reason to use the async version, so deprecating it makes sense).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried out both approaches with @_disfavoredOverload and also @available(*, deprecated). Unfortunately seems both cannot overwrite the preference for async.
Think either we prefix the sync version somehow (like syncFinish) so that it can be shipped in a minor version update or we hold this back until the next major version bump.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think our original assertion that removing the async throws from finish is API breaking may be incorrect.

swift package diagnose-api-breaking-changes does not detect any breaking changes when removing async throws (it does if you add them back). The side effect of removing them is warnings for unused occurrence of try and await.

So -- unless I'm missing something (cc @Lukasa) -- we should just be able to remove async throws from the existing finish().

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm open to removing those if we're confident that nothing breaks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checked that for the internal calls to finish() Bildschirmfoto 2022-10-19 um 17 18 29

Copy link
Collaborator

@glbrntt glbrntt left a comment

Choose a reason for hiding this comment

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

Thanks @schwmi!

@glbrntt glbrntt merged commit 95e6a82 into grpc:main Oct 19, 2022
@schwmi schwmi deleted the improvement/sync-writer-finish branch October 20, 2022 07:53
WendellXY pushed a commit to sundayfun/grpc-swift that referenced this pull request Aug 24, 2023
…rpc#1504)

* Add sync method variant for finishing RequestStreamWriter

* Adjust call sites to use sync RequestStreamWriter finish

* Remove async variant of GRPCAsyncRequestStreamWriter's .finish()

Co-authored-by: George Barnett <gbarnett@apple.com>
pinlin168 pushed a commit to sundayfun/grpc-swift that referenced this pull request Aug 24, 2023
…rpc#1504)

* Add sync method variant for finishing RequestStreamWriter

* Adjust call sites to use sync RequestStreamWriter finish

* Remove async variant of GRPCAsyncRequestStreamWriter's .finish()

Co-authored-by: George Barnett <gbarnett@apple.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants