-
Notifications
You must be signed in to change notification settings - Fork 435
Add a timeout option to blocking send() and receive() calls
#201
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
Conversation
To support default arguments for the timeout, we need to implement this in a convoluted way with a trampoline in a protocol, as protocol methods are not allowed to provide default argument values.
| internal protocol Echo_EchoExpandCall: ClientCallServerStreaming { | ||
| /// Call this to wait for a result. Blocking. | ||
| func receive() throws -> Echo_EchoResponse? | ||
| /// Do not call this directly, call `receive()` in the protocol extension below 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.
Can this be clarified with "private" access control?
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 wish I could, but protocols can't have access modifiers for individual methods. And given that the extension (with the default arguments) should be public, the helper method needs to be, too :-( If someone knows a better way to do this, I'd love to change it!
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.
What benefit do we get from defining methods in protocol extensions instead of generating them directly? It seems that if we generated these methods, then we wouldn't need to expose the "Internal" versions in the protocols.
Would it be idiomatic Swift to use an underscore prefix instead of "Internal" in the helper method names? e.g. "_receive" instead of "receiveInternal"? The leading underscore seems like a more widely-understood indicator that something is private.
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.
As explained before, methods declared in protocols can’t have default arguments, while methods declared in protocol extensions can. So we need to have a method in the extension unless we want users to provide all method arguments for each call.
Good point about the underscores, will look into that.
|
Friendly ping :-) |
|
Replaced "{send,receive}Internal" with "_{send,receive}". Please take another look. |
To support default arguments for the timeout, we need to implement this in a convoluted way with a trampoline in a protocol extension. This is because protocol methods are not allowed to provide default argument values, but protocol extensions are.