mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-07-30 11:48:31 +00:00
33 lines
491 B
Rust
33 lines
491 B
Rust
|
use std::sync::Arc;
|
||
|
|
||
|
use super::KeyValueDatabaseEngine;
|
||
|
|
||
|
pub struct Cork {
|
||
|
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();
|
||
|
}
|
||
|
}
|
||
|
}
|