nlib 0.1.3

Nate's library. Various things or macro patterns I use to aid in more succint Rust programming.
Documentation
use std::time::Duration;

use parking_lot::{Condvar, Mutex};

pub struct Signal {
    mutex: Mutex<bool>,
    cond: Condvar,
}

impl Signal {
    /// Creates a new Signal.
    pub fn new() -> Self {
        Self {
            mutex: Mutex::new(false),
            cond: Condvar::new(),
        }
    }

    /// Signals all waiters.
    pub fn notify(&self) {
        let mut flag = self.mutex.lock();
        *flag = true;

        self.cond.notify_all();
    }

    /// Blocks until signaled.
    pub fn wait(&self) {
        let mut flag = self.mutex.lock();
        while !*flag {
            self.cond.wait(&mut flag);
        }
    }

    /// Blocks until signaled or timeout expires.
    /// Returns `true` if signaled, `false` if timed out.
    pub fn wait_timeout(&self, timeout: Duration) -> bool {
        let mut flag = self.mutex.lock();
        if *flag {
            return true;
        }

        self.cond.wait_for(&mut flag, timeout);

        *flag
    }
}