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
498 B
Rust
Raw Normal View History

2024-04-06 01:24:08 -07:00
use std::sync::Arc;
use super::KeyValueDatabaseEngine;
2024-04-22 23:48:57 -04:00
pub(crate) struct Cork {
2024-04-06 01:24:08 -07:00
db: Arc<dyn KeyValueDatabaseEngine>,
flush: bool,
sync: bool,
}
impl Cork {
pub(crate) fn new(db: &Arc<dyn KeyValueDatabaseEngine>, flush: bool, sync: bool) -> Self {
db.cork().unwrap();
Cork {
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();
}
}
}