-
Notifications
You must be signed in to change notification settings - Fork 435
Add Echo server and client example using async-await API #1278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Echo server and client example using async-await API #1278
Conversation
glbrntt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good aside from a few nits.
Could you also add a note to the README in Sources/Examples/Echo to mention that there are two versions, the original one and this new async/await one?
| /// NOTE: This file should be removed when the `async` branch of `swift-argument-parser` has been | ||
| /// released: https://github.com/apple/swift-argument-parser/tree/async | ||
|
|
||
| #if compiler(>=5.5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: && canImport(_Concurrency) and elsewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 4e909af.
|
|
||
| @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) | ||
| func echoGet(client: Echo_EchoAsyncClient, message: String) async throws { | ||
| async let response = client.get(.with { $0.text = message }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why async let here (and in collect)? Given we await on the next line it would be more idiomatic to await here instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it was more to demonstrate that it's possible for this to be asynchronous. I.e. you could do other things after this line concurrently. But happy to change it. I guess anyone who sees let ... = await ... will know they could swap it for async let ... = ... and await later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 377cd38.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one hasn't been done for 'get'. A victim of the rebase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. Fixed in 3f5ee89.
glbrntt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you rebase onto the 1.4.1-async-await branch as well?
simonjbeaumont
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed the inline comments.
Could you also add a note to the README in Sources/Examples/Echo to mention that there are two versions, the original one and this new async/await one?
Added in 800b72e.
|
|
||
| @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) | ||
| func echoGet(client: Echo_EchoAsyncClient, message: String) async throws { | ||
| async let response = client.get(.with { $0.text = message }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it was more to demonstrate that it's possible for this to be asynchronous. I.e. you could do other things after this line concurrently. But happy to change it. I guess anyone who sees let ... = await ... will know they could swap it for async let ... = ... and await later.
|
|
||
| @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) | ||
| func echoGet(client: Echo_EchoAsyncClient, message: String) async throws { | ||
| async let response = client.get(.with { $0.text = message }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 377cd38.
| /// NOTE: This file should be removed when the `async` branch of `swift-argument-parser` has been | ||
| /// released: https://github.com/apple/swift-argument-parser/tree/async | ||
|
|
||
| #if compiler(>=5.5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 4e909af.
Signed-off-by: Si Beaumont <beaumont@apple.com>
Signed-off-by: Si Beaumont <beaumont@apple.com>
Signed-off-by: Si Beaumont <beaumont@apple.com>
Signed-off-by: Si Beaumont <beaumont@apple.com>
Signed-off-by: Si Beaumont <beaumont@apple.com>
800b72e to
a060723
Compare
|
@glbrntt rebased and retargeted PR for the |
Signed-off-by: Si Beaumont <beaumont@apple.com>
glbrntt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks Si!
This creates a new executable target,
AsyncAwaitEcho, which is equivalent toEchoexcept that is makes use of the new async-await–based client and provider APIs.Signed-off-by: Si Beaumont beaumont@apple.com