diff --git a/core/io/generic.rs b/core/io/generic.rs index 0b0727d8c..8e96f3b6f 100644 --- a/core/io/generic.rs +++ b/core/io/generic.rs @@ -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(()) } diff --git a/core/io/io_uring.rs b/core/io/io_uring.rs index e780e049f..c0c3790de 100644 --- a/core/io/io_uring.rs +++ b/core/io/io_uring.rs @@ -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(); diff --git a/core/io/memory.rs b/core/io/memory.rs index 280d36bd8..b0f7ef6b5 100644 --- a/core/io/memory.rs +++ b/core/io/memory.rs @@ -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(); diff --git a/core/io/mod.rs b/core/io/mod.rs index a700ef819..df399b369 100644 --- a/core/io/mod.rs +++ b/core/io/mod.rs @@ -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 { diff --git a/core/io/unix.rs b/core/io/unix.rs index 2c07cf61b..5e439ee36 100644 --- a/core/io/unix.rs +++ b/core/io/unix.rs @@ -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(); diff --git a/core/io/vfs.rs b/core/io/vfs.rs index 15e5a3853..be0b919fb 100644 --- a/core/io/vfs.rs +++ b/core/io/vfs.rs @@ -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; diff --git a/core/io/windows.rs b/core/io/windows.rs index 3a6349684..e72313973 100644 --- a/core/io/windows.rs +++ b/core/io/windows.rs @@ -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(()) diff --git a/simulator/runner/io.rs b/simulator/runner/io.rs index 2e0de95dc..ca585500a 100644 --- a/simulator/runner/io.rs +++ b/simulator/runner/io.rs @@ -109,13 +109,6 @@ impl IO for SimulatorIO { Ok(file) } - fn wait_for_completion(&self, c: turso_core::Completion) -> Result<()> { - while !c.is_completed() { - self.run_once()?; - } - Ok(()) - } - fn run_once(&self) -> Result<()> { if self.fault.get() { self.nr_run_once_faults