Skip to content

Commit a9d7b5a

Browse files
authored
Make the echo example async by default (#1427)
Motivation: The Echo example has an async and a non-async version. We should reduce it down to just the async version. Modifications: - Move the async example to the directory of the existing non-async example - Add a missing `@main` to the async example Result: Echo example is async
1 parent 31b7551 commit a9d7b5a

File tree

5 files changed

+24
-331
lines changed

5 files changed

+24
-331
lines changed

Package.swift

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -317,23 +317,6 @@ extension Target {
317317
path: "Sources/Examples/Echo/Runtime"
318318
)
319319

320-
static let echoAsync: Target = .executableTarget(
321-
name: "AsyncAwaitEcho",
322-
dependencies: [
323-
.grpc,
324-
.echoModel,
325-
.echoImplementation,
326-
.grpcSampleData,
327-
.nioCore,
328-
.nioPosix,
329-
.logging,
330-
.argumentParser,
331-
].appending(
332-
.nioSSL, if: includeNIOSSL
333-
),
334-
path: "Sources/Examples/Echo/AsyncAwaitRuntime"
335-
)
336-
337320
static let helloWorldModel: Target = .target(
338321
name: "HelloWorldModel",
339322
dependencies: [
@@ -474,7 +457,6 @@ let package = Package(
474457
.echoModel,
475458
.echoImplementation,
476459
.echo,
477-
.echoAsync,
478460
.helloWorldModel,
479461
.helloWorldClient,
480462
.helloWorldServer,

Sources/Examples/Echo/README.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,9 @@ There are four subdirectories:
88
* `Model/` containing the service and model definitions and generated code,
99
* `Implementation/` containing the server implementation of the generated model,
1010
* `Runtime/` containing a CLI for the server and client using the NIO-based APIs.
11-
* `AsyncAwaitRuntime/` containing a CLI for the server and client using the
12-
async-await–based APIs.
1311

1412
### CLI implementation
1513

16-
The SwiftPM targets for the NIO-based CLI and the async-await–based CLI are
17-
`Echo` and `AsyncAwaitEcho` respectively.
18-
19-
The below examples make use the former, with commands of the form:
20-
21-
```sh
22-
swift run Echo ...
23-
```
24-
25-
To use the CLI using the async-await APIs, replace these commands with:
26-
27-
```sh
28-
swift run AsyncAwaitEcho ...
29-
```
30-
3114
### Server
3215

3316
To start the server run:

Sources/Examples/Echo/AsyncAwaitRuntime/Echo.swift renamed to Sources/Examples/Echo/Runtime/Echo.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ enum RPC: String, ExpressibleByArgument {
3636
case update
3737
}
3838

39+
@main
3940
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
4041
struct Echo: AsyncParsableCommand {
4142
static var configuration = CommandConfiguration(
@@ -247,5 +248,10 @@ func echoUpdate(client: Echo_EchoAsyncClient, message: String) async throws {
247248
}
248249

249250
#else
250-
print("ERROR: Concurrency only supported on Swift >= 5.5.")
251+
@main
252+
enum Echo {
253+
static func main() {
254+
print("This example requires Swift >= 5.6")
255+
}
256+
}
251257
#endif
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright 2022, gRPC Authors All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// This file exists to workaround https://github.com/apple/swift/issues/55127.

Sources/Examples/Echo/Runtime/main.swift

Lines changed: 0 additions & 295 deletions
This file was deleted.

0 commit comments

Comments
 (0)