Browse Source

Update tutorials for beta 3 (#2165)

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

---------

Co-authored-by: Gus Cairo <me@gustavocairo.com>
George Barnett 1 year ago
parent
commit
ebcac536a4
15 changed files with 59 additions and 87 deletions
  1. 3 3
      README.md
  2. 2 2
      Sources/GRPCCore/Documentation.docc/Tutorials/Hello-World/Hello-World.tutorial
  3. 3 3
      Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec01-step07-description.swift
  4. 3 3
      Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec01-step08-description.swift
  5. 2 2
      Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step00-package.swift
  6. 3 3
      Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step01-package.swift
  7. 3 3
      Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec05-step02-package.swift
  8. 4 2
      Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step03-create-client.swift
  9. 0 15
      Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step04-run-client.swift
  10. 4 6
      Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step05-stub.swift
  11. 5 7
      Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step06-get-feature.swift
  12. 6 8
      Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step07-list-features.swift
  13. 7 9
      Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step08-record-route.swift
  14. 8 10
      Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step09-route-chat.swift
  15. 6 11
      Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Route-Guide.tutorial

+ 3 - 3
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(

+ 2 - 2
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

+ 3 - 3
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: []
 )

+ 3 - 3
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(

+ 2 - 2
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(

+ 3 - 3
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(

+ 3 - 3
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: [

+ 4 - 2
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
+      // ...
+    }
   }
 }

+ 0 - 15
Sources/GRPCCore/Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec06-step04-run-client.swift

@@ -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()
-  }
-}

+ 4 - 6
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)
+    }
   }
 }

+ 5 - 7
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 {

+ 6 - 8
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 {

+ 7 - 9
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 {

+ 8 - 10
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 {

+ 6 - 11
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 provides 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 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.