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 write a sequence of requests/responses #1499

Merged
merged 2 commits into from
Oct 7, 2022

Conversation

FranzBusch
Copy link
Collaborator

Motivation

We recently adopted the NIOAsyncWriter to back the GRPCAsyncRequestStreamWriter and the GRPCAsyncResponseStreamWriter; however, we did not expose the functionality to write a sequence of the elements that the NIOAsyncWriter offers. This can be useful in cases where you want to write a batch of requests/responses since it reduces the amount of locks and thread hops.

Modification

Expose new methods on the GRPCAsyncRequestStreamWriter and the GRPCAsyncResponseStreamWriter to enable to write a sequence. I also fixed up the comments for the GRPCAsyncRequestStreamWriter since they were outdated.

Result

Users can write a batch of requests/responses.

Comment on lines 78 to 86
@inlinable
public func send<S: Sequence>(
contentsOf requests: S
) async throws where S.Element == (Request, Compression) {
try await self.asyncWriter.yield(contentsOf: requests)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Lukasa @fabianfett What do you think about using the tuple here? Do you prefer creating a new type like MessageWithCompression?

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 almost always in opposition to tuples: nominal types FTW.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fine either way. But generally structs are the better choice for evolving types and APIs. Name should probably be MessageAndCompression? With sounds like the message was already compressed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually I changed the API a bit for now where you can write a sequence of requests/responses and set the compression for all of them. If users ever want to write a sequence with different compression per request/response we can still add that API. WDYT?

# Motivation
We recently adopted the `NIOAsyncWriter` to back the `GRPCAsyncRequestStreamWriter` and the `GRPCAsyncResponseStreamWriter`; however, we did not expose the functionality to write a sequence of the elements that the `NIOAsyncWriter` offers. This can be useful in cases where you want to write a batch of requests/responses since it reduces the amount of locks and thread hops.

# Modification
Expose new methods on the `GRPCAsyncRequestStreamWriter` and the `GRPCAsyncResponseStreamWriter` to enable to write a sequence. I also fixed up the comments for the `GRPCAsyncRequestStreamWriter` since they were outdated.

# Result
Users can write a batch of requests/responses.
@FranzBusch FranzBusch marked this pull request as ready for review October 7, 2022 14:24
@Lukasa Lukasa added the semver-minor ↑ Requires a SemVer Minor version change label Oct 7, 2022
Copy link
Collaborator

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Can we get a unit test to prove this works?

@FranzBusch FranzBusch requested a review from Lukasa October 7, 2022 14:47
@FranzBusch FranzBusch merged commit cfa950f into grpc:main Oct 7, 2022
@FranzBusch FranzBusch deleted the fb-write-sequence branch October 7, 2022 15:45
WendellXY pushed a commit to sundayfun/grpc-swift that referenced this pull request Aug 24, 2023
* Allow to write a sequence of requests/responses

# Motivation
We recently adopted the `NIOAsyncWriter` to back the `GRPCAsyncRequestStreamWriter` and the `GRPCAsyncResponseStreamWriter`; however, we did not expose the functionality to write a sequence of the elements that the `NIOAsyncWriter` offers. This can be useful in cases where you want to write a batch of requests/responses since it reduces the amount of locks and thread hops.

# Modification
Expose new methods on the `GRPCAsyncRequestStreamWriter` and the `GRPCAsyncResponseStreamWriter` to enable to write a sequence. I also fixed up the comments for the `GRPCAsyncRequestStreamWriter` since they were outdated.

# Result
Users can write a batch of requests/responses.

* Update tests
pinlin168 pushed a commit to sundayfun/grpc-swift that referenced this pull request Aug 24, 2023
* Allow to write a sequence of requests/responses

# Motivation
We recently adopted the `NIOAsyncWriter` to back the `GRPCAsyncRequestStreamWriter` and the `GRPCAsyncResponseStreamWriter`; however, we did not expose the functionality to write a sequence of the elements that the `NIOAsyncWriter` offers. This can be useful in cases where you want to write a batch of requests/responses since it reduces the amount of locks and thread hops.

# Modification
Expose new methods on the `GRPCAsyncRequestStreamWriter` and the `GRPCAsyncResponseStreamWriter` to enable to write a sequence. I also fixed up the comments for the `GRPCAsyncRequestStreamWriter` since they were outdated.

# Result
Users can write a batch of requests/responses.

* Update tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-minor ↑ Requires a SemVer Minor version change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants