mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-08 02:34:20 +01:00
default impl for wait_for_completion + check for errors in completion there
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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(())
|
||||
|
||||
Reference in New Issue
Block a user