Atomic notif API shape
⚓ Rust 📅 2026-03-21 👤 surdeus 👁️ 1I have to create a few API's for some callbacks. They are real time audio callbacks and in some cases, it's better to just have a flag to signal another thread to do some work. Like managing the engine that the callback is running on.
I am unsure if my public API is in the best shape. I need some advice.
There's a few types, some with a bool, others like this one measure a delta, but the API is roughly the same.
Is polling something like this the right approach here, or should I be exposing some kind of notifier / wait mechanism instead?
pub struct ProcFramesNotif {
inner: Arc<ProcNotifInner>,
}
struct ProcNotifInner {
frames_processed: AtomicU64,
old_frames: AtomicU64,
}
/// Returns `true` if the process notification has been triggered (edge-triggered).
pub fn peek(&self) -> bool;
/// Clears all tracked progress.
pub fn clear(&self);
/// Returns the number of frames processed since the last call to `take_delta()`.
pub fn take_delta(&self) -> u64;
/// Calls `f` with the newly processed frame count, if any progress is pending.
pub fn take_with<F: FnOnce(u64)>(&self, f: F);
1 post - 1 participant
🏷️ Rust_feed