ndi_sdk_sys/blocking_update.rs
1//! Helper for results of blocking operations with timeout
2
3/// Helper for blocking operations with timeout
4///
5/// ```rust,no_run
6/// # fn main(){
7/// # use std::time::Duration;
8/// # let sender = crate::ndi_sdk_sys::sender::NDISenderBuilder::new().build().unwrap();
9/// let tally = sender.get_tally_update(Duration::from_secs(5));
10/// tally.value; // This contains the current tally state even if nothing changed
11/// if tally.value_updated(){
12/// println!("Tally is now: {:?}", tally.value);
13/// }
14/// # }
15/// ```
16pub struct BlockingUpdate<T> {
17 pub value: T,
18 pub(crate) changed: bool,
19}
20
21impl<T> BlockingUpdate<T> {
22 pub(crate) fn new(value: T, changed: bool) -> Self {
23 BlockingUpdate { value, changed }
24 }
25
26 /// Indicates that the timeout was reached before the operation could finish otherwise
27 pub fn timeout_reached(&self) -> bool {
28 !self.changed
29 }
30
31 /// Indicates that the operation finished within the timeout
32 pub fn value_updated(&self) -> bool {
33 self.changed
34 }
35}