default impl for wait_for_completion + check for errors in completion there

This commit is contained in:
pedrocarlo
2025-08-13 14:43:21 -03:00
parent 002390b5a5
commit f72bcbc5da
8 changed files with 14 additions and 49 deletions

View File

@@ -35,13 +35,6 @@ impl IO for GenericIO {
}))
}
fn wait_for_completion(&self, c: Completion) -> Result<()> {
while !c.is_completed() {
self.run_once()?;
}
Ok(())
}
fn run_once(&self) -> Result<()> {
Ok(())
}

View File

@@ -499,13 +499,6 @@ impl IO for UringIO {
Ok(uring_file)
}
fn wait_for_completion(&self, c: Completion) -> Result<()> {
while !c.is_completed() {
self.run_once()?;
}
Ok(())
}
fn run_once(&self) -> Result<()> {
trace!("run_once()");
let mut inner = self.inner.borrow_mut();

View File

@@ -68,13 +68,6 @@ impl IO for MemoryIO {
Ok(())
}
fn wait_for_completion(&self, c: Completion) -> Result<()> {
while !c.is_completed() {
self.run_once()?;
}
Ok(())
}
fn generate_random_number(&self) -> i64 {
let mut buf = [0u8; 8];
getrandom::getrandom(&mut buf).unwrap();

View File

@@ -82,7 +82,16 @@ pub trait IO: Clock + Send + Sync {
fn run_once(&self) -> Result<()>;
fn wait_for_completion(&self, c: Completion) -> Result<()>;
fn wait_for_completion(&self, c: Completion) -> Result<()> {
while !c.has_error() && !c.is_completed() {
self.run_once()?
}
if c.has_error() {
let err = c.inner.error.get().cloned().unwrap();
return Err(err);
}
Ok(())
}
fn generate_random_number(&self) -> i64;
@@ -194,6 +203,10 @@ impl Completion {
self.inner.is_completed.get()
}
pub fn has_error(&self) -> bool {
self.inner.error.get().is_some()
}
pub fn complete(&self, result: i32) {
if !self.inner.is_completed.get() {
match &self.inner.completion_type {

View File

@@ -399,13 +399,6 @@ impl IO for UnixIO {
Ok(())
}
fn wait_for_completion(&self, c: Completion) -> Result<()> {
while !c.is_completed() {
self.run_once()?;
}
Ok(())
}
fn generate_random_number(&self) -> i64 {
let mut buf = [0u8; 8];
getrandom::getrandom(&mut buf).unwrap();

View File

@@ -44,11 +44,6 @@ impl IO for VfsMod {
Ok(())
}
fn wait_for_completion(&self, _c: Completion) -> Result<()> {
// for the moment anyway, this is currently a sync api
Ok(())
}
fn generate_random_number(&self) -> i64 {
if self.ctx.is_null() {
return -1;

View File

@@ -31,14 +31,6 @@ impl IO for WindowsIO {
}))
}
#[instrument(err, skip_all, level = Level::TRACE)]
fn wait_for_completion(&self, c: Completion) -> Result<()> {
while !c.is_completed() {
self.run_once()?;
}
Ok(())
}
#[instrument(err, skip_all, level = Level::TRACE)]
fn run_once(&self) -> Result<()> {
Ok(())