Files
continuwuity/src/database/cork.rs
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

33 lines
484 B
Rust
Raw Normal View History

2024-04-06 01:24:08 -07:00
use std::sync::Arc;
use super::KeyValueDatabaseEngine;
2024-05-09 15:59:08 -07:00
pub struct Cork {
2024-04-06 01:24:08 -07:00
db: Arc<dyn KeyValueDatabaseEngine>,
flush: bool,
sync: bool,
}
impl Cork {
2024-05-09 15:59:08 -07:00
pub fn new(db: &Arc<dyn KeyValueDatabaseEngine>, flush: bool, sync: bool) -> Self {
2024-04-06 01:24:08 -07:00
db.cork().unwrap();
2024-06-09 10:23:06 +00:00
Self {
2024-04-06 01:24:08 -07:00
db: db.clone(),
flush,
sync,
}
}
}
impl Drop for Cork {
fn drop(&mut self) {
self.db.uncork().ok();
if self.flush {
self.db.flush().ok();
}
if self.sync {
self.db.sync().ok();
}
}
}