use super::requests::IoRequest;
use bytes::Bytes;
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use std::task::{Context, Poll};
pub(super) struct UringReadFuture {
pub(super) request: Arc<IoRequest>,
}
impl Future for UringReadFuture {
type Output = object_store::Result<Bytes>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let mut state = self.request.state.lock().unwrap();
if state.completed {
match state.err.take() {
Some(err) => Poll::Ready(Err(object_store::Error::Generic {
store: "io_uring",
source: Box::new(err),
})),
None => {
let br = state.bytes_read;
state.buffer.truncate(br);
let bytes = std::mem::take(&mut state.buffer).freeze();
Poll::Ready(Ok(bytes))
}
}
} else {
state.waker = Some(cx.waker().clone());
Poll::Pending
}
}
}