only add the sync completion after we call sync in the closure

This commit is contained in:
pedrocarlo
2025-07-10 15:55:08 -03:00
parent 0ab2f2b951
commit 6088aa34c2

View File

@@ -209,15 +209,20 @@ impl File for SimulatorFile {
}
let c = if let Some(latency) = self.generate_latency_duration() {
let cloned_c = c.clone();
let op = Box::new(|file: &SimulatorFile| file.inner.sync(cloned_c));
let op = Box::new(|file: &SimulatorFile| -> Result<_> {
let c = file.inner.sync(cloned_c)?;
*file.sync_completion.borrow_mut() = Some(c.clone());
Ok(c)
});
self.queued_io
.borrow_mut()
.push(DelayedIo { time: latency, op });
Ok(c)
c
} else {
self.inner.sync(c)
}?;
*self.sync_completion.borrow_mut() = Some(c.clone());
let c = self.inner.sync(c)?;
*self.sync_completion.borrow_mut() = Some(c.clone());
c
};
Ok(c)
}