From d463fe915b8c1041d5a91fe71d970f5de7dbba61 Mon Sep 17 00:00:00 2001 From: George Barnett Date: Fri, 17 Jan 2025 15:13:48 +0000 Subject: [PATCH] Update tutorials for beta 3 Motivation: We're going to tag beta 3 soon, so ensure the tutorials are up to date. Modifications: - Update tutorials Result: More up-to-date docs --- README.md | 6 +++--- .../Tutorials/Hello-World/Hello-World.tutorial | 4 ++-- .../route-guide-sec01-step07-description.swift | 6 +++--- .../route-guide-sec01-step08-description.swift | 6 +++--- .../route-guide-sec05-step00-package.swift | 4 ++-- .../route-guide-sec05-step01-package.swift | 6 +++--- .../route-guide-sec05-step02-package.swift | 6 +++--- ...oute-guide-sec06-step03-create-client.swift | 6 ++++-- .../route-guide-sec06-step04-run-client.swift | 15 --------------- .../route-guide-sec06-step05-stub.swift | 10 ++++------ .../route-guide-sec06-step06-get-feature.swift | 12 +++++------- ...oute-guide-sec06-step07-list-features.swift | 14 ++++++-------- ...route-guide-sec06-step08-record-route.swift | 16 +++++++--------- .../route-guide-sec06-step09-route-chat.swift | 18 ++++++++---------- .../Tutorials/Route-Guide/Route-Guide.tutorial | 17 ++++++----------- 15 files changed, 59 insertions(+), 87 deletions(-) delete mode 100644 Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step04-run-client.swift diff --git a/README.md b/README.md index 82e23d403..d641ed824 100644 --- a/README.md +++ b/README.md @@ -32,9 +32,9 @@ let package = Package( name: "foo-package", platforms: [.macOS("15.0")], dependencies: [ - .package(url: "https://github.com/grpc/grpc-swift.git", from: "2.0.0-beta.2"), - .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", from: "1.0.0-beta.2"), - .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", from: "1.0.0-beta.2"), + .package(url: "https://github.com/grpc/grpc-swift.git", from: "2.0.0-beta.3"), + .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", from: "1.0.0-beta.3"), + .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", from: "1.0.0-beta.3"), ], targets: [ .executableTarget( diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Hello-World/Hello-World.tutorial b/Sources/GRPCCore/Documentation.docc/Tutorials/Hello-World/Hello-World.tutorial index 31273ed0b..4818c18ae 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Hello-World/Hello-World.tutorial +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Hello-World/Hello-World.tutorial @@ -1,6 +1,6 @@ @Tutorial(time: 10) { @XcodeRequirement( - title: "Xcode 16 Beta 5+", + title: "Xcode 16", destination: "https://developer.apple.com/download/" ) @@ -18,7 +18,7 @@ repository by running the following command in a terminal: ```console - git clone --branch 2.0.0-beta.2 https://github.com/grpc/grpc-swift + git clone --branch 2.0.0-beta.3 https://github.com/grpc/grpc-swift ``` You then need to change directory to the `Examples/hello-world` directory of the cloned diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec01-step07-description.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec01-step07-description.swift index 662795346..2f1fb0bd3 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec01-step07-description.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec01-step07-description.swift @@ -5,9 +5,9 @@ let package = Package( name: "RouteGuide", platforms: [.macOS(.v15)], dependencies: [ - .package(url: "https://github.com/grpc/grpc-swift.git", from: "2.0.0-beta.2"), - .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", from: "1.0.0-beta.2"), - .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", from: "1.0.0-beta.2"), + .package(url: "https://github.com/grpc/grpc-swift.git", from: "2.0.0-beta.3"), + .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", from: "1.0.0-beta.3"), + .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", from: "1.0.0-beta.3"), ], targets: [] ) diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec01-step08-description.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec01-step08-description.swift index 55dab65b4..dcb3ced86 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec01-step08-description.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec01-step08-description.swift @@ -5,9 +5,9 @@ let package = Package( name: "RouteGuide", platforms: [.macOS(.v15)], dependencies: [ - .package(url: "https://github.com/grpc/grpc-swift.git", from: "2.0.0-beta.2"), - .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", from: "1.0.0-beta.2"), - .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", from: "1.0.0-beta.2"), + .package(url: "https://github.com/grpc/grpc-swift.git", from: "2.0.0-beta.3"), + .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", from: "1.0.0-beta.3"), + .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", from: "1.0.0-beta.3"), ], targets: [ .executableTarget( diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step00-package.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step00-package.swift index 7deea7e81..6aaa5f7a7 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step00-package.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step00-package.swift @@ -5,8 +5,8 @@ let package = Package( name: "RouteGuide", platforms: [.macOS(.v15)], dependencies: [ - .package(url: "https://github.com/grpc/grpc-swift.git", from: "2.0.0-beta.2"), - .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", from: "1.0.0-beta.2"), + .package(url: "https://github.com/grpc/grpc-swift.git", from: "2.0.0-beta.3"), + .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", from: "1.0.0-beta.3"), ], targets: [ .executableTarget( diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step01-package.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step01-package.swift index 67cf80691..a450a82e4 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step01-package.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step01-package.swift @@ -5,9 +5,9 @@ let package = Package( name: "RouteGuide", platforms: [.macOS(.v15)], dependencies: [ - .package(url: "https://github.com/grpc/grpc-swift.git", from: "2.0.0-beta.2"), - .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", from: "1.0.0-beta.2"), - .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", from: "1.0.0-beta.2"), + .package(url: "https://github.com/grpc/grpc-swift.git", from: "2.0.0-beta.3"), + .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", from: "1.0.0-beta.3"), + .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", from: "1.0.0-beta.3"), ], targets: [ .executableTarget( diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step02-package.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step02-package.swift index 8462eada5..b250e8d82 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step02-package.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step02-package.swift @@ -5,9 +5,9 @@ let package = Package( name: "RouteGuide", platforms: [.macOS(.v15)], dependencies: [ - .package(url: "https://github.com/grpc/grpc-swift.git", from: "2.0.0-beta.2"), - .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", from: "1.0.0-beta.2"), - .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", from: "1.0.0-beta.2"), + .package(url: "https://github.com/grpc/grpc-swift.git", from: "2.0.0-beta.3"), + .package(url: "https://github.com/grpc/grpc-swift-protobuf.git", from: "1.0.0-beta.3"), + .package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", from: "1.0.0-beta.3"), .package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"), ], targets: [ diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step03-create-client.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step03-create-client.swift index bf1dbaebc..55f110792 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step03-create-client.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step03-create-client.swift @@ -3,11 +3,13 @@ import GRPCNIOTransportHTTP2 extension RouteGuide { func runClient() async throws { - let client = try GRPCClient( + try await withGRPCClient( transport: .http2NIOPosix( target: .ipv4(host: "127.0.0.1", port: 31415), transportSecurity: .plaintext ) - ) + ) { client in + // ... + } } } diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step04-run-client.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step04-run-client.swift deleted file mode 100644 index 52c4c79e5..000000000 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step04-run-client.swift +++ /dev/null @@ -1,15 +0,0 @@ -import GRPCCore -import GRPCNIOTransportHTTP2 - -extension RouteGuide { - func runClient() async throws { - let client = try GRPCClient( - transport: .http2NIOPosix( - target: .ipv4(host: "127.0.0.1", port: 31415), - transportSecurity: .plaintext - ) - ) - - async let _ = client.run() - } -} diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step05-stub.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step05-stub.swift index 9b8b5ee3b..94bca0e04 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step05-stub.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step05-stub.swift @@ -3,15 +3,13 @@ import GRPCNIOTransportHTTP2 extension RouteGuide { func runClient() async throws { - let client = try GRPCClient( + try await withGRPCClient( transport: .http2NIOPosix( target: .ipv4(host: "127.0.0.1", port: 31415), transportSecurity: .plaintext ) - ) - - async let _ = client.run() - - let routeGuide = Routeguide_RouteGuide.Client(wrapping: client) + ) { client in + let routeGuide = Routeguide_RouteGuide.Client(wrapping: client) + } } } diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step06-get-feature.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step06-get-feature.swift index b2b103b20..e985f8189 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step06-get-feature.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step06-get-feature.swift @@ -3,17 +3,15 @@ import GRPCNIOTransportHTTP2 extension RouteGuide { func runClient() async throws { - let client = try GRPCClient( + try await withGRPCClient( transport: .http2NIOPosix( target: .ipv4(host: "127.0.0.1", port: 31415), transportSecurity: .plaintext ) - ) - - async let _ = client.run() - - let routeGuide = Routeguide_RouteGuide.Client(wrapping: client) - try await self.getFeature(using: routeGuide) + ) { client in + let routeGuide = Routeguide_RouteGuide.Client(wrapping: client) + try await self.getFeature(using: routeGuide) + } } private func getFeature(using routeGuide: Routeguide_RouteGuide.Client) async throws { diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step07-list-features.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step07-list-features.swift index 609ce0ead..ba990eede 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step07-list-features.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step07-list-features.swift @@ -3,18 +3,16 @@ import GRPCNIOTransportHTTP2 extension RouteGuide { func runClient() async throws { - let client = try GRPCClient( + try await withGRPCClient( transport: .http2NIOPosix( target: .ipv4(host: "127.0.0.1", port: 31415), transportSecurity: .plaintext ) - ) - - async let _ = client.run() - - let routeGuide = Routeguide_RouteGuide.Client(wrapping: client) - try await self.getFeature(using: routeGuide) - try await self.listFeatures(using: routeGuide) + ) { client in + let routeGuide = Routeguide_RouteGuide.Client(wrapping: client) + try await self.getFeature(using: routeGuide) + try await self.listFeatures(using: routeGuide) + } } private func getFeature(using routeGuide: Routeguide_RouteGuide.Client) async throws { diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step08-record-route.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step08-record-route.swift index 9fb6490c8..8bf4f71ee 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step08-record-route.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step08-record-route.swift @@ -3,19 +3,17 @@ import GRPCNIOTransportHTTP2 extension RouteGuide { func runClient() async throws { - let client = try GRPCClient( + try await withGRPCClient( transport: .http2NIOPosix( target: .ipv4(host: "127.0.0.1", port: 31415), transportSecurity: .plaintext ) - ) - - async let _ = client.run() - - let routeGuide = Routeguide_RouteGuide.Client(wrapping: client) - try await self.getFeature(using: routeGuide) - try await self.listFeatures(using: routeGuide) - try await self.recordRoute(using: routeGuide) + ) { client in + let routeGuide = Routeguide_RouteGuide.Client(wrapping: client) + try await self.getFeature(using: routeGuide) + try await self.listFeatures(using: routeGuide) + try await self.recordRoute(using: routeGuide) + } } private func getFeature(using routeGuide: Routeguide_RouteGuide.Client) async throws { diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step09-route-chat.swift b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step09-route-chat.swift index 9f1afac60..81d7cfac9 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step09-route-chat.swift +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step09-route-chat.swift @@ -3,20 +3,18 @@ import GRPCNIOTransportHTTP2 extension RouteGuide { func runClient() async throws { - let client = try GRPCClient( + try await withGRPCClient( transport: .http2NIOPosix( target: .ipv4(host: "127.0.0.1", port: 31415), transportSecurity: .plaintext ) - ) - - async let _ = client.run() - - let routeGuide = Routeguide_RouteGuide.Client(wrapping: client) - try await self.getFeature(using: routeGuide) - try await self.listFeatures(using: routeGuide) - try await self.recordRoute(using: routeGuide) - try await self.routeChat(using: routeGuide) + ) { client in + let routeGuide = Routeguide_RouteGuide.Client(wrapping: client) + try await self.getFeature(using: routeGuide) + try await self.listFeatures(using: routeGuide) + try await self.recordRoute(using: routeGuide) + try await self.routeChat(using: routeGuide) + } } private func getFeature(using routeGuide: Routeguide_RouteGuide.Client) async throws { diff --git a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Route-Guide.tutorial b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Route-Guide.tutorial index 3491b521a..061a0bbdb 100644 --- a/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Route-Guide.tutorial +++ b/Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Route-Guide.tutorial @@ -1,6 +1,6 @@ @Tutorial(time: 30) { @XcodeRequirement( - title: "Xcode 16 Beta 6+", + title: "Xcode 16", destination: "https://developer.apple.com/download/" ) @@ -401,20 +401,15 @@ } @Step { - First we need to create a gRPC client for our stub, we're not using TLS so we - use the `.plaintext` security transport and specify the server address and port - we want to connect to. + We need to create a gRPC client for our stub. gRPC provide a with-style helper to + manage the lifecycle of the client and its transport so let's use that. We specify the + transport to use which and configure it appropriately. We're not using TLS so we use + the `.plaintext` security transport and specify the server address and port we want to + connect to. @Code(name: "Sources/RouteGuide+Client.swift", file: "route-guide-sec06-step03-create-client.swift") } - @Step { - To make RPCs using the client it needs to be running. Running the client will resolve the - target address, start a load balancer and then maintain connections to the server. - - @Code(name: "Sources/RouteGuide+Client.swift", file: "route-guide-sec06-step04-run-client.swift") - } - @Step { We can now instantiate the stub with our `client` and call service methods.