Skip to content

Commit 706519c

Browse files
committed
Update examples
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 706519c

File tree

16 files changed

+58
-129
lines changed

16 files changed

+58
-129
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,4 +991,4 @@ extension Echo_Echo.ClientProtocol {
991991
onResponse: handleResponse
992992
)
993993
}
994-
}
994+
}

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/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: [

Examples/hello-world/Sources/Subcommands/Greet.swift

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,12 @@ struct Greet: AsyncParsableCommand {
2929
var name: String = ""
3030

3131
func run() async throws {
32-
try await withThrowingDiscardingTaskGroup { group in
33-
let client = GRPCClient(
34-
transport: try .http2NIOPosix(
35-
target: .ipv4(host: "127.0.0.1", port: self.port),
36-
transportSecurity: .plaintext
37-
)
32+
try await withGRPCClient(
33+
transport: .http2NIOPosix(
34+
target: .ipv4(host: "127.0.0.1", port: self.port),
35+
transportSecurity: .plaintext
3836
)
39-
40-
group.addTask {
41-
try await client.run()
42-
}
43-
44-
defer {
45-
client.beginGracefulShutdown()
46-
}
47-
37+
) { client in
4838
let greeter = Helloworld_Greeter.Client(wrapping: client)
4939
let reply = try await greeter.sayHello(.with { $0.name = self.name })
5040
print(reply.message)

0 commit comments

Comments
 (0)