Skip to content

Commit b143369

Browse files
authored
Update examples (#2163)
Motivation: We changed a few API across the packages so the examples need to be brought up-to-date. Modifications: - Update generated code - Update dependencies - Fix warnings Result: Examples are up-to-date
1 parent 93d0536 commit b143369

File tree

20 files changed

+77
-148
lines changed

20 files changed

+77
-148
lines changed

Examples/echo/Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ let package = Package(
2121
name: "echo",
2222
platforms: [.macOS("15.0")],
2323
dependencies: [
24-
.package(url: "https://github.com/grpc/grpc-swift.git", exact: "2.0.0-beta.2"),
25-
.package(url: "https://github.com/grpc/grpc-swift-protobuf.git", exact: "1.0.0-beta.2"),
26-
.package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", exact: "1.0.0-beta.2"),
24+
.package(url: "https://github.com/grpc/grpc-swift.git", branch: "main"),
25+
.package(url: "https://github.com/grpc/grpc-swift-protobuf.git", branch: "main"),
26+
.package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", branch: "main"),
2727
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0"),
2828
],
2929
targets: [

Examples/echo/Sources/Generated/echo.grpc.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ extension Echo_Echo {
347347

348348
// Default implementation of 'registerMethods(with:)'.
349349
extension Echo_Echo.StreamingServiceProtocol {
350-
internal func registerMethods(with router: inout GRPCCore.RPCRouter) {
350+
internal func registerMethods<Transport>(with router: inout GRPCCore.RPCRouter<Transport>) where Transport: GRPCCore.ServerTransport {
351351
router.registerHandler(
352352
forMethod: Echo_Echo.Method.Get.descriptor,
353353
deserializer: GRPCProtobuf.ProtobufDeserializer<Echo_EchoRequest>(),
@@ -600,14 +600,14 @@ extension Echo_Echo {
600600
/// The ``Client`` provides an implementation of ``ClientProtocol`` which wraps
601601
/// a `GRPCCore.GRPCCClient`. The underlying `GRPCClient` provides the long-lived
602602
/// means of communication with the remote peer.
603-
internal struct Client: ClientProtocol {
604-
private let client: GRPCCore.GRPCClient
603+
internal struct Client<Transport>: ClientProtocol where Transport: GRPCCore.ClientTransport {
604+
private let client: GRPCCore.GRPCClient<Transport>
605605

606606
/// Creates a new client wrapping the provided `GRPCCore.GRPCClient`.
607607
///
608608
/// - Parameters:
609609
/// - client: A `GRPCCore.GRPCClient` providing a communication channel to the service.
610-
internal init(wrapping client: GRPCCore.GRPCClient) {
610+
internal init(wrapping client: GRPCCore.GRPCClient<Transport>) {
611611
self.client = client
612612
}
613613

Examples/echo/Sources/Subcommands/Collect.swift

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,12 @@ struct Collect: AsyncParsableCommand {
2727
var arguments: ClientArguments
2828

2929
func run() async throws {
30-
let client = GRPCClient(
31-
transport: try .http2NIOPosix(
30+
try await withGRPCClient(
31+
transport: .http2NIOPosix(
3232
target: self.arguments.target,
3333
transportSecurity: .plaintext
3434
)
35-
)
36-
37-
try await withThrowingDiscardingTaskGroup { group in
38-
group.addTask {
39-
try await client.run()
40-
}
41-
35+
) { client in
4236
let echo = Echo_Echo.Client(wrapping: client)
4337

4438
for _ in 0 ..< self.arguments.repetitions {
@@ -50,8 +44,6 @@ struct Collect: AsyncParsableCommand {
5044
}
5145
print("collect ← \(message.text)")
5246
}
53-
54-
client.beginGracefulShutdown()
5547
}
5648
}
5749
}

Examples/echo/Sources/Subcommands/Expand.swift

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,12 @@ struct Expand: AsyncParsableCommand {
2727
var arguments: ClientArguments
2828

2929
func run() async throws {
30-
let client = GRPCClient(
31-
transport: try .http2NIOPosix(
30+
try await withGRPCClient(
31+
transport: .http2NIOPosix(
3232
target: self.arguments.target,
3333
transportSecurity: .plaintext
3434
)
35-
)
36-
37-
try await withThrowingDiscardingTaskGroup { group in
38-
group.addTask {
39-
try await client.run()
40-
}
41-
35+
) { client in
4236
let echo = Echo_Echo.Client(wrapping: client)
4337

4438
for _ in 0 ..< self.arguments.repetitions {
@@ -50,8 +44,6 @@ struct Expand: AsyncParsableCommand {
5044
}
5145
}
5246
}
53-
54-
client.beginGracefulShutdown()
5547
}
5648
}
5749
}

Examples/echo/Sources/Subcommands/Get.swift

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,12 @@ struct Get: AsyncParsableCommand {
2525
var arguments: ClientArguments
2626

2727
func run() async throws {
28-
let client = GRPCClient(
29-
transport: try .http2NIOPosix(
28+
try await withGRPCClient(
29+
transport: .http2NIOPosix(
3030
target: self.arguments.target,
3131
transportSecurity: .plaintext
3232
)
33-
)
34-
35-
try await withThrowingDiscardingTaskGroup { group in
36-
group.addTask {
37-
try await client.run()
38-
}
39-
33+
) { client in
4034
let echo = Echo_Echo.Client(wrapping: client)
4135

4236
for _ in 0 ..< self.arguments.repetitions {
@@ -45,8 +39,6 @@ struct Get: AsyncParsableCommand {
4539
let response = try await echo.get(message)
4640
print("get ← \(response.text)")
4741
}
48-
49-
client.beginGracefulShutdown()
5042
}
5143
}
5244
}

Examples/echo/Sources/Subcommands/Update.swift

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,12 @@ struct Update: AsyncParsableCommand {
2727
var arguments: ClientArguments
2828

2929
func run() async throws {
30-
let client = GRPCClient(
31-
transport: try .http2NIOPosix(
30+
try await withGRPCClient(
31+
transport: .http2NIOPosix(
3232
target: self.arguments.target,
3333
transportSecurity: .plaintext
3434
)
35-
)
36-
37-
try await withThrowingDiscardingTaskGroup { group in
38-
group.addTask {
39-
try await client.run()
40-
}
41-
35+
) { client in
4236
let echo = Echo_Echo.Client(wrapping: client)
4337

4438
for _ in 0 ..< self.arguments.repetitions {
@@ -53,8 +47,6 @@ struct Update: AsyncParsableCommand {
5347
}
5448
}
5549
}
56-
57-
client.beginGracefulShutdown()
5850
}
5951
}
6052
}

Examples/error-details/Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ let package = Package(
2121
name: "error-details",
2222
platforms: [.macOS(.v15)],
2323
dependencies: [
24-
.package(url: "https://github.com/grpc/grpc-swift.git", exact: "2.0.0-beta.2"),
25-
.package(url: "https://github.com/grpc/grpc-swift-protobuf.git", exact: "1.0.0-beta.2"),
24+
.package(url: "https://github.com/grpc/grpc-swift.git", branch: "main"),
25+
.package(url: "https://github.com/grpc/grpc-swift-protobuf.git", branch: "main"),
2626
],
2727
targets: [
2828
.executableTarget(

Examples/error-details/Sources/DetailedErrorExample.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct DetailedErrorExample {
2929
}
3030
}
3131

32-
static func doRPC(_ greeter: Helloworld_Greeter.Client) async throws {
32+
static func doRPC(_ greeter: Helloworld_Greeter.Client<some ClientTransport>) async throws {
3333
do {
3434
let reply = try await greeter.sayHello(.with { $0.name = "(ignored)" })
3535
print("Unexpected reply: \(reply.message)")

Examples/error-details/Sources/Generated/helloworld.grpc.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ extension Helloworld_Greeter {
156156

157157
// Default implementation of 'registerMethods(with:)'.
158158
extension Helloworld_Greeter.StreamingServiceProtocol {
159-
internal func registerMethods(with router: inout GRPCCore.RPCRouter) {
159+
internal func registerMethods<Transport>(with router: inout GRPCCore.RPCRouter<Transport>) where Transport: GRPCCore.ServerTransport {
160160
router.registerHandler(
161161
forMethod: Helloworld_Greeter.Method.SayHello.descriptor,
162162
deserializer: GRPCProtobuf.ProtobufDeserializer<Helloworld_HelloRequest>(),
@@ -246,14 +246,14 @@ extension Helloworld_Greeter {
246246
/// > Source IDL Documentation:
247247
/// >
248248
/// > The greeting service definition.
249-
internal struct Client: ClientProtocol {
250-
private let client: GRPCCore.GRPCClient
249+
internal struct Client<Transport>: ClientProtocol where Transport: GRPCCore.ClientTransport {
250+
private let client: GRPCCore.GRPCClient<Transport>
251251

252252
/// Creates a new client wrapping the provided `GRPCCore.GRPCClient`.
253253
///
254254
/// - Parameters:
255255
/// - client: A `GRPCCore.GRPCClient` providing a communication channel to the service.
256-
internal init(wrapping client: GRPCCore.GRPCClient) {
256+
internal init(wrapping client: GRPCCore.GRPCClient<Transport>) {
257257
self.client = client
258258
}
259259

Examples/hello-world/Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ let package = Package(
2121
name: "hello-world",
2222
platforms: [.macOS("15.0")],
2323
dependencies: [
24-
.package(url: "https://github.com/grpc/grpc-swift.git", exact: "2.0.0-beta.2"),
25-
.package(url: "https://github.com/grpc/grpc-swift-protobuf.git", exact: "1.0.0-beta.2"),
26-
.package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", exact: "1.0.0-beta.2"),
24+
.package(url: "https://github.com/grpc/grpc-swift.git", branch: "main"),
25+
.package(url: "https://github.com/grpc/grpc-swift-protobuf.git", branch: "main"),
26+
.package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", branch: "main"),
2727
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0"),
2828
],
2929
targets: [

0 commit comments

Comments
 (0)