Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Examples/echo/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
8 changes: 4 additions & 4 deletions Examples/echo/Sources/Generated/echo.grpc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Transport>(with router: inout GRPCCore.RPCRouter<Transport>) where Transport: GRPCCore.ServerTransport {
router.registerHandler(
forMethod: Echo_Echo.Method.Get.descriptor,
deserializer: GRPCProtobuf.ProtobufDeserializer<Echo_EchoRequest>(),
Expand Down Expand Up @@ -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<Transport>: ClientProtocol where Transport: GRPCCore.ClientTransport {
private let client: GRPCCore.GRPCClient<Transport>

/// 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<Transport>) {
self.client = client
}

Expand Down
14 changes: 3 additions & 11 deletions Examples/echo/Sources/Subcommands/Collect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -50,8 +44,6 @@ struct Collect: AsyncParsableCommand {
}
print("collect ← \(message.text)")
}

client.beginGracefulShutdown()
}
}
}
14 changes: 3 additions & 11 deletions Examples/echo/Sources/Subcommands/Expand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -50,8 +44,6 @@ struct Expand: AsyncParsableCommand {
}
}
}

client.beginGracefulShutdown()
}
}
}
14 changes: 3 additions & 11 deletions Examples/echo/Sources/Subcommands/Get.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -45,8 +39,6 @@ struct Get: AsyncParsableCommand {
let response = try await echo.get(message)
print("get ← \(response.text)")
}

client.beginGracefulShutdown()
}
}
}
14 changes: 3 additions & 11 deletions Examples/echo/Sources/Subcommands/Update.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -53,8 +47,6 @@ struct Update: AsyncParsableCommand {
}
}
}

client.beginGracefulShutdown()
}
}
}
4 changes: 2 additions & 2 deletions Examples/error-details/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion Examples/error-details/Sources/DetailedErrorExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct DetailedErrorExample {
}
}

static func doRPC(_ greeter: Helloworld_Greeter.Client) async throws {
static func doRPC(_ greeter: Helloworld_Greeter.Client<some ClientTransport>) async throws {
do {
let reply = try await greeter.sayHello(.with { $0.name = "(ignored)" })
print("Unexpected reply: \(reply.message)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Transport>(with router: inout GRPCCore.RPCRouter<Transport>) where Transport: GRPCCore.ServerTransport {
router.registerHandler(
forMethod: Helloworld_Greeter.Method.SayHello.descriptor,
deserializer: GRPCProtobuf.ProtobufDeserializer<Helloworld_HelloRequest>(),
Expand Down Expand Up @@ -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<Transport>: ClientProtocol where Transport: GRPCCore.ClientTransport {
private let client: GRPCCore.GRPCClient<Transport>

/// 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<Transport>) {
self.client = client
}

Expand Down
6 changes: 3 additions & 3 deletions Examples/hello-world/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
8 changes: 4 additions & 4 deletions Examples/hello-world/Sources/Generated/helloworld.grpc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Transport>(with router: inout GRPCCore.RPCRouter<Transport>) where Transport: GRPCCore.ServerTransport {
router.registerHandler(
forMethod: Helloworld_Greeter.Method.SayHello.descriptor,
deserializer: GRPCProtobuf.ProtobufDeserializer<Helloworld_HelloRequest>(),
Expand Down Expand Up @@ -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<Transport>: ClientProtocol where Transport: GRPCCore.ClientTransport {
private let client: GRPCCore.GRPCClient<Transport>

/// 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<Transport>) {
self.client = client
}

Expand Down
20 changes: 5 additions & 15 deletions Examples/hello-world/Sources/Subcommands/Greet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions Examples/reflection-server/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
8 changes: 4 additions & 4 deletions Examples/reflection-server/Sources/Generated/echo.grpc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Transport>(with router: inout GRPCCore.RPCRouter<Transport>) where Transport: GRPCCore.ServerTransport {
router.registerHandler(
forMethod: Echo_Echo.Method.Get.descriptor,
deserializer: GRPCProtobuf.ProtobufDeserializer<Echo_EchoRequest>(),
Expand Down Expand Up @@ -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<Transport>: ClientProtocol where Transport: GRPCCore.ClientTransport {
private let client: GRPCCore.GRPCClient<Transport>

/// 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<Transport>) {
self.client = client
}

Expand Down
6 changes: 3 additions & 3 deletions Examples/route-guide/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
8 changes: 4 additions & 4 deletions Examples/route-guide/Sources/Generated/route_guide.grpc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Transport>(with router: inout GRPCCore.RPCRouter<Transport>) where Transport: GRPCCore.ServerTransport {
router.registerHandler(
forMethod: Routeguide_RouteGuide.Method.GetFeature.descriptor,
deserializer: GRPCProtobuf.ProtobufDeserializer<Routeguide_Point>(),
Expand Down Expand Up @@ -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<Transport>: ClientProtocol where Transport: GRPCCore.ClientTransport {
private let client: GRPCCore.GRPCClient<Transport>

/// 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<Transport>) {
self.client = client
}

Expand Down
19 changes: 6 additions & 13 deletions Examples/route-guide/Sources/Subcommands/GetFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -62,8 +57,6 @@ struct GetFeature: AsyncParsableCommand {
} else {
print("Found '\(feature.name)' at (\(self.latitude), \(self.longitude))")
}

client.beginGracefulShutdown()
}
}
}
Loading
Loading