Files
ldm0 0099465abc feat(parkable-image): add managed encoded image parking
Adopt completed image buffers, protect readers with snapshots, and park encoded bytes into one disk extent with a reusable backup. Keep resident and parked registries separate, expose owner-driven deadlines and force parking, and synchronize notifications with a short-lock waiting flag. Include lifecycle, concurrency, scheduling, and failure regressions with documentation and runnable examples.
2026-09-21 16:47:19 +08:00

31 lines
1.2 KiB
Rust

//! Drive one parking deadline with a custom policy and synthetic image bytes.
//!
//! Run with `cargo run -p moli-parkable-image --example deadline`.
//!
//! This single-threaded, one-shot wait is not a concurrent scheduler.
//! Concurrent owners must also react to new_with_schedule_wakeup() notifications.
use std::time::{Duration, Instant};
use moli_disk_pool::DiskPool;
use moli_parkable_image::{ParkableImageManager, ParkableImagePolicy};
fn main() -> std::io::Result<()> {
let policy = ParkableImagePolicy {
parking_delay: Duration::from_millis(10),
..ParkableImagePolicy::default()
};
let manager = ParkableImageManager::new(Some(DiskPool::new(None)?), policy);
let image = manager.from_frozen_bytes(vec![3; 4096]);
let deadline = manager.next_parking_deadline().expect("image is eligible");
std::thread::sleep(deadline.saturating_duration_since(Instant::now()));
manager.park_images();
assert_eq!(image.retained_memory_bytes(), 0);
assert_eq!(manager.diagnostics().parked_count, 1);
assert!(manager.next_parking_deadline().is_none());
println!("Parked the image at its deadline; no further deadline is scheduled.");
Ok(())
}