Skip to content

Conversation

@rebello95
Copy link
Collaborator

Adds support to allow consumers to specify a Channel when creating ServiceClient instances.

This is something already supported by other gRPC language flavors (like Python), and alleviates the need to create a new channel every time a call is made.

Usage:

let sharedChannel = Channel(address: "https://api.myservice.com", secure: true)
HelloWorldClient(channel: sharedChannel).getHelloWorld(...)
OtherClient(channel: sharedChannel).getOther(...)

Resolves #200

Adds support to allow consumers to specify a `Channel` when creating `ServiceClient` instances.

This is something already supported by other gRPC language flavors (like [Python](https://github.com/grpc/grpc/blob/7542ba6e0caee740f124dc25706287fd62f546d8/examples/python/multiplex/multiplex_client.py#L110)), and alleviates the need to create a new channel every time a call is made.

Usage:
```swift
let sharedChannel = Channel(address: "https://api.myservice.com", secure: true)
HelloWorldClient(channel: sharedChannel).getHelloWorld(...)
OtherClient(channel: sharedChannel).getOther(...)
```

Resolves grpc#200
@rebello95
Copy link
Collaborator Author

@MrMage if you'd like to take a look 😀

Thought about adding additional tests for this as well, but it looks like reusing channels is already covered here. Let me know if you think there's something I should add!

Copy link
Collaborator

@MrMage MrMage left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks, Michael! This is indeed sort-of covered by gRPCTests, but those tests are very generic and tests many things at once. So I would indeed appreciate a small dedicated test (in EchoTests or a new file ServiceClientTests, I'd say) that specifically tests using two ServiceClients with the same channel. Something like this:

let channel = Channel(...)
do {
    let client = EchoClient(channel: channel)
    XCTAssertEqual("foo", client.get(...).text)
}
// First client has left scope by now.
do {
    let client = EchoClient(channel: channel)
    XCTAssertEqual("foo", client.get(...).text)
}

Hope that makes sense.


/// Create a client using a pre-defined channel.
public init(channel: Channel) {
gRPC.initialize()
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 we can remove this gRPC.initialize() call, given that this is now done by Channel.init. Also in the other constructors above and below.

Also, I'd suggest moving this constructor below or above all the other ones?

@timburks
Copy link
Member

timburks commented Apr 6, 2018

LGTM.

Thanks @rebello95 for adding this, and @MrMage for reviewing! I agree that future tests would be important for this, but will merge this now.

@timburks timburks merged commit f10a8ec into grpc:master Apr 6, 2018
@rebello95 rebello95 deleted the channel-specification branch April 6, 2018 15:48
rebello95 added a commit to rebello95/grpc-swift that referenced this pull request Apr 6, 2018
Adds tests for support added in grpc#202 that allows `ServiceClient` instances to share a single `Channel`.
@rebello95
Copy link
Collaborator Author

Thank you for the feedback @MrMage and @timburks! As this is already merged, I went ahead and wrote some tests in #203 that should cover it

rebello95 added a commit to rebello95/grpc-swift that referenced this pull request Apr 6, 2018
Adds tests for support added in grpc#202 that allows `ServiceClient` instances to share a single `Channel`.
IceRocky pushed a commit to IceRocky/grpc-swift that referenced this pull request May 28, 2024
Adds tests for support added in grpc/grpc-swift#202 that allows `ServiceClient` instances to share a single `Channel`.
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