-
Notifications
You must be signed in to change notification settings - Fork 436
Improve the names of a few commonly used APIs #2014
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,7 @@ struct Expand: AsyncParsableCommand { | |
} | ||
} | ||
|
||
client.close() | ||
client.beginGracefulShutdown() | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,7 @@ struct Update: AsyncParsableCommand { | |
} | ||
} | ||
|
||
client.close() | ||
client.beginGracefulShutdown() | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,7 +79,7 @@ struct ListFeatures: AsyncParsableCommand { | |
} | ||
} | ||
|
||
client.close() | ||
client.beginGracefulShutdown() | ||
} | ||
|
||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,7 +68,7 @@ struct RecordRoute: AsyncParsableCommand { | |
""" | ||
print(text) | ||
|
||
client.close() | ||
client.beginGracefulShutdown() | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,7 +68,7 @@ struct RouteChat: AsyncParsableCommand { | |
} | ||
} | ||
|
||
client.close() | ||
client.beginGracefulShutdown() | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,11 +60,11 @@ internal import Atomics | |
/// | ||
/// ```swift | ||
/// // Start running the server. | ||
/// try await server.run() | ||
/// try await server.serve() | ||
/// ``` | ||
/// | ||
/// The ``run()`` method won't return until the server has finished handling all requests. You can | ||
/// signal to the server that it should stop accepting new requests by calling ``stopListening()``. | ||
/// signal to the server that it should stop accepting new requests by calling ``beginGracefulShutdown()``. | ||
/// This allows the server to drain existing requests gracefully. To stop the server more abruptly | ||
/// you can cancel the task running your server. If your application requires additional resources | ||
/// that need their lifecycles managed you should consider using [Swift Service | ||
|
@@ -154,13 +154,13 @@ public struct GRPCServer: Sendable { | |
/// | ||
/// This function returns when the configured transport has stopped listening and all requests have been | ||
/// handled. You can signal to the transport that it should stop listening by calling | ||
/// ``stopListening()``. The server will continue to process existing requests. | ||
/// ``beginGracefulShutdown()``. The server will continue to process existing requests. | ||
/// | ||
/// To stop the server more abruptly you can cancel the task that this function is running in. | ||
/// | ||
/// - Note: You can only call this function once, repeated calls will result in a | ||
/// ``RuntimeError`` being thrown. | ||
public func run() async throws { | ||
public func serve() async throws { | ||
let (wasNotStarted, actualState) = self.state.compareExchange( | ||
expected: .notStarted, | ||
desired: .running, | ||
|
@@ -209,15 +209,15 @@ public struct GRPCServer: Sendable { | |
/// against this server. Once the server has processed all requests the ``run()`` method returns. | ||
/// | ||
/// Calling this on a server which is already stopping or has stopped has no effect. | ||
public func stopListening() { | ||
public func beginGracefulShutdown() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest using |
||
let (wasRunning, actual) = self.state.compareExchange( | ||
expected: .running, | ||
desired: .stopping, | ||
ordering: .sequentiallyConsistent | ||
) | ||
|
||
if wasRunning { | ||
self.transport.stopListening() | ||
self.transport.beginGracefulShutdown() | ||
} else { | ||
switch actual { | ||
case .notStarted: | ||
|
@@ -229,7 +229,7 @@ public struct GRPCServer: Sendable { | |
|
||
// Lost a race with 'run()', try again. | ||
if !exchanged { | ||
self.stopListening() | ||
self.beginGracefulShutdown() | ||
} | ||
|
||
case .running: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
I am a bit wary of renaming this from
run
toserve
. While I understand what you are getting at. We do have many libraries that now adopted therun
method name to align with whatLifecycle
expects. If you rename this here and conform toService
in the future your type will have two methods that do the same.Uh oh!
There was an error while loading. Please reload this page.
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.
FWIW I agree with Franz here, I think it is more important to be consistent with the rest of the ecosystem on this.
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.
run
is less clear and is worse for users which don't depend on lifecycle. Users would have to provide shims to useLifecycle
anyway (to avoid retroactive conformance). If we provide conformance in the future (e.g. via package traits) then having arun()
method calling through toserve()
isn't an issue.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.
From the perspective of a user using
Lifecycle
the names of these methods don't matter at all because they won't be called directly by the user.From the perspective of a user not using
Lifecycle
, these methods matter a lot: they will be called by the user so they should be clear.Uh oh!
There was an error while loading. Please reload this page.
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.
I still remain unconvinced.
serve
andrun
are pretty close in my mind. Even leavingLifecycle
aside just the proliferation ofrun
methods across the ecosystem is IMO enough to justify aligning. It becomes very natural that you callrun
on your server/clients when you don't use something likeLifecycle
.I don't want to block this PR on this and you can merge over my unconvincedness.
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.
Noted. I'm pretty strongly against aligning for the sake of aligning on a generic name: I think we should pick names that express their intent and provide the most clarity, the APIs should be approachable for all users including those new to Swift and SoS!