diff --git a/Examples/echo/Package.swift b/Examples/echo/Package.swift index bdbf47403..224fff79c 100644 --- a/Examples/echo/Package.swift +++ b/Examples/echo/Package.swift @@ -21,9 +21,9 @@ let package = Package( name: "echo", platforms: [.macOS("15.0")], dependencies: [ - .package(url: "https://github.com/grpc/grpc-swift.git", exact: "2.0.0-beta.2"), - .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", exact: "1.0.0-beta.2"), - .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", exact: "1.0.0-beta.2"), + .package(url: "https://github.com/grpc/grpc-swift.git", branch: "main"), + .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", branch: "main"), + .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", branch: "main"), .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0"), ], targets: [ diff --git a/Examples/echo/Sources/Generated/echo.grpc.swift b/Examples/echo/Sources/Generated/echo.grpc.swift index 26c075247..3a0e70694 100644 --- a/Examples/echo/Sources/Generated/echo.grpc.swift +++ b/Examples/echo/Sources/Generated/echo.grpc.swift @@ -347,7 +347,7 @@ extension Echo_Echo { // Default implementation of 'registerMethods(with:)'. extension Echo_Echo.StreamingServiceProtocol { - internal func registerMethods(with router: inout GRPCCore.RPCRouter) { + internal func registerMethods(with router: inout GRPCCore.RPCRouter) where Transport: GRPCCore.ServerTransport { router.registerHandler( forMethod: Echo_Echo.Method.Get.descriptor, deserializer: GRPCProtobuf.ProtobufDeserializer(), @@ -600,14 +600,14 @@ extension Echo_Echo { /// The ``Client`` provides an implementation of ``ClientProtocol`` which wraps /// a `GRPCCore.GRPCCClient`. The underlying `GRPCClient` provides the long-lived /// means of communication with the remote peer. - internal struct Client: ClientProtocol { - private let client: GRPCCore.GRPCClient + internal struct Client: ClientProtocol where Transport: GRPCCore.ClientTransport { + private let client: GRPCCore.GRPCClient /// Creates a new client wrapping the provided `GRPCCore.GRPCClient`. /// /// - Parameters: /// - client: A `GRPCCore.GRPCClient` providing a communication channel to the service. - internal init(wrapping client: GRPCCore.GRPCClient) { + internal init(wrapping client: GRPCCore.GRPCClient) { self.client = client } diff --git a/Examples/echo/Sources/Subcommands/Collect.swift b/Examples/echo/Sources/Subcommands/Collect.swift index 281ae9d35..27350774a 100644 --- a/Examples/echo/Sources/Subcommands/Collect.swift +++ b/Examples/echo/Sources/Subcommands/Collect.swift @@ -27,18 +27,12 @@ struct Collect: AsyncParsableCommand { var arguments: ClientArguments func run() async throws { - let client = GRPCClient( - transport: try .http2NIOPosix( + try await withGRPCClient( + transport: .http2NIOPosix( target: self.arguments.target, transportSecurity: .plaintext ) - ) - - try await withThrowingDiscardingTaskGroup { group in - group.addTask { - try await client.run() - } - + ) { client in let echo = Echo_Echo.Client(wrapping: client) for _ in 0 ..< self.arguments.repetitions { @@ -50,8 +44,6 @@ struct Collect: AsyncParsableCommand { } print("collect ← \(message.text)") } - - client.beginGracefulShutdown() } } } diff --git a/Examples/echo/Sources/Subcommands/Expand.swift b/Examples/echo/Sources/Subcommands/Expand.swift index c30b481ef..b488c9977 100644 --- a/Examples/echo/Sources/Subcommands/Expand.swift +++ b/Examples/echo/Sources/Subcommands/Expand.swift @@ -27,18 +27,12 @@ struct Expand: AsyncParsableCommand { var arguments: ClientArguments func run() async throws { - let client = GRPCClient( - transport: try .http2NIOPosix( + try await withGRPCClient( + transport: .http2NIOPosix( target: self.arguments.target, transportSecurity: .plaintext ) - ) - - try await withThrowingDiscardingTaskGroup { group in - group.addTask { - try await client.run() - } - + ) { client in let echo = Echo_Echo.Client(wrapping: client) for _ in 0 ..< self.arguments.repetitions { @@ -50,8 +44,6 @@ struct Expand: AsyncParsableCommand { } } } - - client.beginGracefulShutdown() } } } diff --git a/Examples/echo/Sources/Subcommands/Get.swift b/Examples/echo/Sources/Subcommands/Get.swift index 9a1953628..4c429910c 100644 --- a/Examples/echo/Sources/Subcommands/Get.swift +++ b/Examples/echo/Sources/Subcommands/Get.swift @@ -25,18 +25,12 @@ struct Get: AsyncParsableCommand { var arguments: ClientArguments func run() async throws { - let client = GRPCClient( - transport: try .http2NIOPosix( + try await withGRPCClient( + transport: .http2NIOPosix( target: self.arguments.target, transportSecurity: .plaintext ) - ) - - try await withThrowingDiscardingTaskGroup { group in - group.addTask { - try await client.run() - } - + ) { client in let echo = Echo_Echo.Client(wrapping: client) for _ in 0 ..< self.arguments.repetitions { @@ -45,8 +39,6 @@ struct Get: AsyncParsableCommand { let response = try await echo.get(message) print("get ← \(response.text)") } - - client.beginGracefulShutdown() } } } diff --git a/Examples/echo/Sources/Subcommands/Update.swift b/Examples/echo/Sources/Subcommands/Update.swift index 8e8cb664f..726e8b83d 100644 --- a/Examples/echo/Sources/Subcommands/Update.swift +++ b/Examples/echo/Sources/Subcommands/Update.swift @@ -27,18 +27,12 @@ struct Update: AsyncParsableCommand { var arguments: ClientArguments func run() async throws { - let client = GRPCClient( - transport: try .http2NIOPosix( + try await withGRPCClient( + transport: .http2NIOPosix( target: self.arguments.target, transportSecurity: .plaintext ) - ) - - try await withThrowingDiscardingTaskGroup { group in - group.addTask { - try await client.run() - } - + ) { client in let echo = Echo_Echo.Client(wrapping: client) for _ in 0 ..< self.arguments.repetitions { @@ -53,8 +47,6 @@ struct Update: AsyncParsableCommand { } } } - - client.beginGracefulShutdown() } } } diff --git a/Examples/error-details/Package.swift b/Examples/error-details/Package.swift index ffd3f85a0..2598c8d80 100644 --- a/Examples/error-details/Package.swift +++ b/Examples/error-details/Package.swift @@ -21,8 +21,8 @@ let package = Package( name: "error-details", platforms: [.macOS(.v15)], dependencies: [ - .package(url: "https://github.com/grpc/grpc-swift.git", exact: "2.0.0-beta.2"), - .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", exact: "1.0.0-beta.2"), + .package(url: "https://github.com/grpc/grpc-swift.git", branch: "main"), + .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", branch: "main"), ], targets: [ .executableTarget( diff --git a/Examples/error-details/Sources/DetailedErrorExample.swift b/Examples/error-details/Sources/DetailedErrorExample.swift index ddd669877..f4bfa464c 100644 --- a/Examples/error-details/Sources/DetailedErrorExample.swift +++ b/Examples/error-details/Sources/DetailedErrorExample.swift @@ -29,7 +29,7 @@ struct DetailedErrorExample { } } - static func doRPC(_ greeter: Helloworld_Greeter.Client) async throws { + static func doRPC(_ greeter: Helloworld_Greeter.Client) async throws { do { let reply = try await greeter.sayHello(.with { $0.name = "(ignored)" }) print("Unexpected reply: \(reply.message)") diff --git a/Examples/error-details/Sources/Generated/helloworld.grpc.swift b/Examples/error-details/Sources/Generated/helloworld.grpc.swift index 737d5fa0f..329c0e816 100644 --- a/Examples/error-details/Sources/Generated/helloworld.grpc.swift +++ b/Examples/error-details/Sources/Generated/helloworld.grpc.swift @@ -156,7 +156,7 @@ extension Helloworld_Greeter { // Default implementation of 'registerMethods(with:)'. extension Helloworld_Greeter.StreamingServiceProtocol { - internal func registerMethods(with router: inout GRPCCore.RPCRouter) { + internal func registerMethods(with router: inout GRPCCore.RPCRouter) where Transport: GRPCCore.ServerTransport { router.registerHandler( forMethod: Helloworld_Greeter.Method.SayHello.descriptor, deserializer: GRPCProtobuf.ProtobufDeserializer(), @@ -246,14 +246,14 @@ extension Helloworld_Greeter { /// > Source IDL Documentation: /// > /// > The greeting service definition. - internal struct Client: ClientProtocol { - private let client: GRPCCore.GRPCClient + internal struct Client: ClientProtocol where Transport: GRPCCore.ClientTransport { + private let client: GRPCCore.GRPCClient /// Creates a new client wrapping the provided `GRPCCore.GRPCClient`. /// /// - Parameters: /// - client: A `GRPCCore.GRPCClient` providing a communication channel to the service. - internal init(wrapping client: GRPCCore.GRPCClient) { + internal init(wrapping client: GRPCCore.GRPCClient) { self.client = client } diff --git a/Examples/hello-world/Package.swift b/Examples/hello-world/Package.swift index c73f1433d..f4f32f991 100644 --- a/Examples/hello-world/Package.swift +++ b/Examples/hello-world/Package.swift @@ -21,9 +21,9 @@ let package = Package( name: "hello-world", platforms: [.macOS("15.0")], dependencies: [ - .package(url: "https://github.com/grpc/grpc-swift.git", exact: "2.0.0-beta.2"), - .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", exact: "1.0.0-beta.2"), - .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", exact: "1.0.0-beta.2"), + .package(url: "https://github.com/grpc/grpc-swift.git", branch: "main"), + .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", branch: "main"), + .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", branch: "main"), .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0"), ], targets: [ diff --git a/Examples/hello-world/Sources/Generated/helloworld.grpc.swift b/Examples/hello-world/Sources/Generated/helloworld.grpc.swift index 737d5fa0f..329c0e816 100644 --- a/Examples/hello-world/Sources/Generated/helloworld.grpc.swift +++ b/Examples/hello-world/Sources/Generated/helloworld.grpc.swift @@ -156,7 +156,7 @@ extension Helloworld_Greeter { // Default implementation of 'registerMethods(with:)'. extension Helloworld_Greeter.StreamingServiceProtocol { - internal func registerMethods(with router: inout GRPCCore.RPCRouter) { + internal func registerMethods(with router: inout GRPCCore.RPCRouter) where Transport: GRPCCore.ServerTransport { router.registerHandler( forMethod: Helloworld_Greeter.Method.SayHello.descriptor, deserializer: GRPCProtobuf.ProtobufDeserializer(), @@ -246,14 +246,14 @@ extension Helloworld_Greeter { /// > Source IDL Documentation: /// > /// > The greeting service definition. - internal struct Client: ClientProtocol { - private let client: GRPCCore.GRPCClient + internal struct Client: ClientProtocol where Transport: GRPCCore.ClientTransport { + private let client: GRPCCore.GRPCClient /// Creates a new client wrapping the provided `GRPCCore.GRPCClient`. /// /// - Parameters: /// - client: A `GRPCCore.GRPCClient` providing a communication channel to the service. - internal init(wrapping client: GRPCCore.GRPCClient) { + internal init(wrapping client: GRPCCore.GRPCClient) { self.client = client } diff --git a/Examples/hello-world/Sources/Subcommands/Greet.swift b/Examples/hello-world/Sources/Subcommands/Greet.swift index cf5d73a8d..643c90798 100644 --- a/Examples/hello-world/Sources/Subcommands/Greet.swift +++ b/Examples/hello-world/Sources/Subcommands/Greet.swift @@ -29,22 +29,12 @@ struct Greet: AsyncParsableCommand { var name: String = "" func run() async throws { - try await withThrowingDiscardingTaskGroup { group in - let client = GRPCClient( - transport: try .http2NIOPosix( - target: .ipv4(host: "127.0.0.1", port: self.port), - transportSecurity: .plaintext - ) + try await withGRPCClient( + transport: .http2NIOPosix( + target: .ipv4(host: "127.0.0.1", port: self.port), + transportSecurity: .plaintext ) - - group.addTask { - try await client.run() - } - - defer { - client.beginGracefulShutdown() - } - + ) { client in let greeter = Helloworld_Greeter.Client(wrapping: client) let reply = try await greeter.sayHello(.with { $0.name = self.name }) print(reply.message) diff --git a/Examples/reflection-server/Package.swift b/Examples/reflection-server/Package.swift index 8a8041fcf..37a3942b2 100644 --- a/Examples/reflection-server/Package.swift +++ b/Examples/reflection-server/Package.swift @@ -21,10 +21,10 @@ let package = Package( name: "reflection-server", platforms: [.macOS(.v15)], dependencies: [ - .package(url: "https://github.com/grpc/grpc-swift.git", exact: "2.0.0-beta.2"), - .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", exact: "1.0.0-beta.2"), - .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", exact: "1.0.0-beta.2"), - .package(url: "https://github.com/grpc/grpc-swift-extras.git", exact: "1.0.0-beta.2"), + .package(url: "https://github.com/grpc/grpc-swift.git", branch: "main"), + .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", branch: "main"), + .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", branch: "main"), + .package(url: "https://github.com/grpc/grpc-swift-extras.git", branch: "main"), .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0"), ], targets: [ diff --git a/Examples/reflection-server/Sources/Generated/echo.grpc.swift b/Examples/reflection-server/Sources/Generated/echo.grpc.swift index 26c075247..3a0e70694 100644 --- a/Examples/reflection-server/Sources/Generated/echo.grpc.swift +++ b/Examples/reflection-server/Sources/Generated/echo.grpc.swift @@ -347,7 +347,7 @@ extension Echo_Echo { // Default implementation of 'registerMethods(with:)'. extension Echo_Echo.StreamingServiceProtocol { - internal func registerMethods(with router: inout GRPCCore.RPCRouter) { + internal func registerMethods(with router: inout GRPCCore.RPCRouter) where Transport: GRPCCore.ServerTransport { router.registerHandler( forMethod: Echo_Echo.Method.Get.descriptor, deserializer: GRPCProtobuf.ProtobufDeserializer(), @@ -600,14 +600,14 @@ extension Echo_Echo { /// The ``Client`` provides an implementation of ``ClientProtocol`` which wraps /// a `GRPCCore.GRPCCClient`. The underlying `GRPCClient` provides the long-lived /// means of communication with the remote peer. - internal struct Client: ClientProtocol { - private let client: GRPCCore.GRPCClient + internal struct Client: ClientProtocol where Transport: GRPCCore.ClientTransport { + private let client: GRPCCore.GRPCClient /// Creates a new client wrapping the provided `GRPCCore.GRPCClient`. /// /// - Parameters: /// - client: A `GRPCCore.GRPCClient` providing a communication channel to the service. - internal init(wrapping client: GRPCCore.GRPCClient) { + internal init(wrapping client: GRPCCore.GRPCClient) { self.client = client } diff --git a/Examples/route-guide/Package.swift b/Examples/route-guide/Package.swift index d9ee1b592..bf26e8ffe 100644 --- a/Examples/route-guide/Package.swift +++ b/Examples/route-guide/Package.swift @@ -21,9 +21,9 @@ let package = Package( name: "route-guide", platforms: [.macOS("15.0")], dependencies: [ - .package(url: "https://github.com/grpc/grpc-swift.git", exact: "2.0.0-beta.2"), - .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", exact: "1.0.0-beta.2"), - .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", exact: "1.0.0-beta.2"), + .package(url: "https://github.com/grpc/grpc-swift.git", branch: "main"), + .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", branch: "main"), + .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", branch: "main"), .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0"), ], targets: [ diff --git a/Examples/route-guide/Sources/Generated/route_guide.grpc.swift b/Examples/route-guide/Sources/Generated/route_guide.grpc.swift index 05b5e3c48..87ef9ba8b 100644 --- a/Examples/route-guide/Sources/Generated/route_guide.grpc.swift +++ b/Examples/route-guide/Sources/Generated/route_guide.grpc.swift @@ -407,7 +407,7 @@ extension Routeguide_RouteGuide { // Default implementation of 'registerMethods(with:)'. extension Routeguide_RouteGuide.StreamingServiceProtocol { - internal func registerMethods(with router: inout GRPCCore.RPCRouter) { + internal func registerMethods(with router: inout GRPCCore.RPCRouter) where Transport: GRPCCore.ServerTransport { router.registerHandler( forMethod: Routeguide_RouteGuide.Method.GetFeature.descriptor, deserializer: GRPCProtobuf.ProtobufDeserializer(), @@ -684,14 +684,14 @@ extension Routeguide_RouteGuide { /// > Source IDL Documentation: /// > /// > Interface exported by the server. - internal struct Client: ClientProtocol { - private let client: GRPCCore.GRPCClient + internal struct Client: ClientProtocol where Transport: GRPCCore.ClientTransport { + private let client: GRPCCore.GRPCClient /// Creates a new client wrapping the provided `GRPCCore.GRPCClient`. /// /// - Parameters: /// - client: A `GRPCCore.GRPCClient` providing a communication channel to the service. - internal init(wrapping client: GRPCCore.GRPCClient) { + internal init(wrapping client: GRPCCore.GRPCClient) { self.client = client } diff --git a/Examples/route-guide/Sources/Subcommands/GetFeature.swift b/Examples/route-guide/Sources/Subcommands/GetFeature.swift index eb58eeff3..6ea6a12bd 100644 --- a/Examples/route-guide/Sources/Subcommands/GetFeature.swift +++ b/Examples/route-guide/Sources/Subcommands/GetFeature.swift @@ -37,17 +37,12 @@ struct GetFeature: AsyncParsableCommand { var longitude: Int32 = -746_143_763 func run() async throws { - let transport = try HTTP2ClientTransport.Posix( - target: .ipv4(host: "127.0.0.1", port: self.port), - transportSecurity: .plaintext - ) - let client = GRPCClient(transport: transport) - - try await withThrowingDiscardingTaskGroup { group in - group.addTask { - try await client.run() - } - + try await withGRPCClient( + transport: .http2NIOPosix( + target: .ipv4(host: "127.0.0.1", port: self.port), + transportSecurity: .plaintext + ) + ) { client in let routeGuide = Routeguide_RouteGuide.Client(wrapping: client) let point = Routeguide_Point.with { @@ -62,8 +57,6 @@ struct GetFeature: AsyncParsableCommand { } else { print("Found '\(feature.name)' at (\(self.latitude), \(self.longitude))") } - - client.beginGracefulShutdown() } } } diff --git a/Examples/route-guide/Sources/Subcommands/ListFeatures.swift b/Examples/route-guide/Sources/Subcommands/ListFeatures.swift index 32db2d0c1..be6d754dc 100644 --- a/Examples/route-guide/Sources/Subcommands/ListFeatures.swift +++ b/Examples/route-guide/Sources/Subcommands/ListFeatures.swift @@ -51,17 +51,12 @@ struct ListFeatures: AsyncParsableCommand { var maxLongitude: Int32 = -730_000_000 func run() async throws { - let transport = try HTTP2ClientTransport.Posix( - target: .ipv4(host: "127.0.0.1", port: self.port), - transportSecurity: .plaintext - ) - let client = GRPCClient(transport: transport) - - try await withThrowingDiscardingTaskGroup { group in - group.addTask { - try await client.run() - } - + try await withGRPCClient( + transport: .http2NIOPosix( + target: .ipv4(host: "127.0.0.1", port: self.port), + transportSecurity: .plaintext + ) + ) { client in let routeGuide = Routeguide_RouteGuide.Client(wrapping: client) let boundingRectangle = Routeguide_Rectangle.with { $0.lo.latitude = self.minLatitude @@ -78,9 +73,6 @@ struct ListFeatures: AsyncParsableCommand { print("(\(count)) \(feature.name) at (\(lat), \(lon))") } } - - client.beginGracefulShutdown() } - } } diff --git a/Examples/route-guide/Sources/Subcommands/RecordRoute.swift b/Examples/route-guide/Sources/Subcommands/RecordRoute.swift index bc3f4f9dc..7a652206c 100644 --- a/Examples/route-guide/Sources/Subcommands/RecordRoute.swift +++ b/Examples/route-guide/Sources/Subcommands/RecordRoute.swift @@ -30,17 +30,12 @@ struct RecordRoute: AsyncParsableCommand { var points: Int = 10 func run() async throws { - let transport = try HTTP2ClientTransport.Posix( - target: .ipv4(host: "127.0.0.1", port: self.port), - transportSecurity: .plaintext - ) - let client = GRPCClient(transport: transport) - - try await withThrowingDiscardingTaskGroup { group in - group.addTask { - try await client.run() - } - + try await withGRPCClient( + transport: .http2NIOPosix( + target: .ipv4(host: "127.0.0.1", port: self.port), + transportSecurity: .plaintext + ) + ) { client in let routeGuide = Routeguide_RouteGuide.Client(wrapping: client) // Get all features. @@ -67,8 +62,6 @@ struct RecordRoute: AsyncParsableCommand { a distance \(summary.distance) metres. """ print(text) - - client.beginGracefulShutdown() } } } diff --git a/Examples/route-guide/Sources/Subcommands/RouteChat.swift b/Examples/route-guide/Sources/Subcommands/RouteChat.swift index 2a4c23b16..ba6d92424 100644 --- a/Examples/route-guide/Sources/Subcommands/RouteChat.swift +++ b/Examples/route-guide/Sources/Subcommands/RouteChat.swift @@ -30,17 +30,12 @@ struct RouteChat: AsyncParsableCommand { var port: Int = 31415 func run() async throws { - let transport = try HTTP2ClientTransport.Posix( - target: .ipv4(host: "127.0.0.1", port: self.port), - transportSecurity: .plaintext - ) - let client = GRPCClient(transport: transport) - - try await withThrowingDiscardingTaskGroup { group in - group.addTask { - try await client.run() - } - + try await withGRPCClient( + transport: .http2NIOPosix( + target: .ipv4(host: "127.0.0.1", port: self.port), + transportSecurity: .plaintext + ) + ) { client in let routeGuide = Routeguide_RouteGuide.Client(wrapping: client) try await routeGuide.routeChat { writer in @@ -67,8 +62,6 @@ struct RouteChat: AsyncParsableCommand { print("Received note: '\(note.message) at (\(lat), \(lon))'") } } - - client.beginGracefulShutdown() } } }