-
Notifications
You must be signed in to change notification settings - Fork 824
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
Refactor to share code between do_put and do_exchange calls #5728
Conversation
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.
Thanks @opensourcegeek -- this looks like nice progress
arrow-flight/src/client.rs
Outdated
@@ -704,3 +679,75 @@ impl FlightClient { | |||
request | |||
} | |||
} | |||
|
|||
struct FallibleRequestStream { |
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 to me 👍
Perhaps we could add some comments about what this struct is doing and what it is for.
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 did refactor it so that this is generic and not tied to request stream itself, is it worth moving this bit of code to some internal_utils module? Happy to leave it where it is atm
arrow-flight/src/client.rs
Outdated
fn poll_next(self: std::pin::Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> std::task::Poll<Option<Self::Item>> { | ||
let pinned = self.get_mut(); | ||
let mut request_streams = pinned.request_streams.as_mut(); | ||
match request_streams.poll_next_unpin(cx) { |
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 think you can avoid a level of nesting using the ready!
macro here
so like
match ready!(request_streams.poll_next_unpin(cx) {
Some(Ok(data)) => ...
Some(Err(e)) => ...
None => ...
}
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 did expand the macro from original code for my own understanding, I'll tidy it up. Thanks
arrow-flight/src/client.rs
Outdated
return Poll::Ready(Some(Err(err))); | ||
}; | ||
|
||
match pinned.response_streams.poll_next_unpin(cx) { |
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.
Likewise here, calling ready!()
can probably simplify this a bit
6a8fc13
to
3806b5a
Compare
3806b5a
to
7729b20
Compare
Signed-off-by: Praveen Kumar <[email protected]>
7729b20
to
9b8b42b
Compare
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.
Thanks @opensourcegeek -- I think this is a very nice improvement to me. 🙏
match ready!(request_streams.poll_next_unpin(cx)) { | ||
Some(Ok(data)) => Poll::Ready(Some(data)), | ||
Some(Err(e)) => { | ||
// unwrap() here is safe, ownership of sender will |
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.
Another potential improvement might be to do something like
if let Some(sender) = pinned.sender.take() {
sender.send();
}
And that way avoid a panic
However, I see this unwrap is simply moved here from elsewhere in the PR so I think we can improve it in the future
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.
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.
Ah good point, it would've taken less time to swap the code than writing the justification comments.
@@ -704,3 +674,99 @@ impl FlightClient { | |||
request | |||
} | |||
} | |||
|
|||
/// Wrapper around fallible stream such that when |
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.
BTW I especially appreciate the understandable comments in this PR 🙏
Which issue does this PR close?
Extends on work done for #3462 - internal refactor
Rationale for this change
Internal refactor to allow sharing of the code between do_put and do_exchange methods in arrow-flight
What changes are included in this PR?
Refactored the poll_fn repetitions to use separate fallible streams for request and response streams.
Are there any user-facing changes?
No