Xuanwo commented on code in PR #5835:
URL: https://github.com/apache/arrow-rs/pull/5835#discussion_r1636658846
##########
object_store/src/buffered.rs:
##########
@@ -289,6 +289,58 @@ impl BufWriter {
}
}
+ /// Write data to the writer in [`Bytes`].
+ ///
+ /// Unlike [`AsyncWrite::poll_write`], `put` can write data without extra
copying.
+ ///
+ /// This API is recommended while the data source generates [`Bytes`].
+ pub async fn put(&mut self, bytes: Bytes) -> crate::Result<()> {
+ loop {
+ return match &mut self.state {
+ BufWriterState::Write(Some(write)) => {
+ write.wait_for_capacity(self.max_concurrency).await?;
+ write.put(bytes);
+ Ok(())
+ }
+ BufWriterState::Write(None) | BufWriterState::Flush(_) => {
+ panic!("Already shut down")
+ }
+ // NOTE
+ //
+ // This case should never happen in practice, but rust async
API does
+ // make it possible for users to call `put` before
`poll_write` returns `Ready`.
+ //
+ // We allow such usage by `await` the future and continue the
loop.
+ BufWriterState::Prepare(f) => {
+ self.state = BufWriterState::Write(f.await?.into());
+ continue;
+ }
+ BufWriterState::Buffer(path, b) => {
Review Comment:
The problem here is I want to avoid the extra cost of `Box::pin(fut)` by
awaiting it in place.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]