mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-08-04 18:18:03 +00:00
Implement trait Clock
for implemented IOs
Replace `chrono::Local::now()` to return `Instant` but containing same info
This commit is contained in:
parent
8d6d50d9d5
commit
2873c36b31
7 changed files with 65 additions and 20 deletions
|
@ -18,6 +18,7 @@ use std::{
|
|||
sync::Arc,
|
||||
};
|
||||
use tracing::{debug, trace};
|
||||
use crate::io::clock::{Clock, Instant};
|
||||
|
||||
struct OwnedCallbacks(UnsafeCell<Callbacks>);
|
||||
// We assume we locking on IO level is done by user.
|
||||
|
@ -183,6 +184,16 @@ impl UnixIO {
|
|||
}
|
||||
}
|
||||
|
||||
impl Clock for UnixIO {
|
||||
fn now(&self) -> Instant {
|
||||
let now = chrono::Local::now();
|
||||
Instant {
|
||||
secs: now.timestamp(),
|
||||
micros: now.timestamp_subsec_micros(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IO for UnixIO {
|
||||
fn open_file(&self, path: &str, flags: OpenFlags, _direct: bool) -> Result<Arc<dyn File>> {
|
||||
trace!("open_file(path = {})", path);
|
||||
|
@ -247,10 +258,6 @@ impl IO for UnixIO {
|
|||
getrandom::getrandom(&mut buf).unwrap();
|
||||
i64::from_ne_bytes(buf)
|
||||
}
|
||||
|
||||
fn get_current_time(&self) -> String {
|
||||
chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string()
|
||||
}
|
||||
}
|
||||
|
||||
enum CompletionCallback {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue