//! Skipper module.
use std::sync::Arc;
use tokio::sync::Mutex;
/// Utility to skip N Actions over chosen Pipelines,
/// when you exactly know that they have no need to re-run after changes
#[derive(Clone)]
pub struct Skipper(Arc<Mutex<usize>>);
impl Default for Skipper {
fn default() -> Self {
Self(Arc::new(Mutex::new(0usize)))
}
}
impl Skipper {
/// Creates a new skipper.
pub fn new(skip: usize) -> Self {
Self(Arc::new(Mutex::new(skip)))
}
/// Checks if skipper has non-empty counter. It also decreases the counter, if has.
pub async fn skip(&self) -> bool {
let mut guard = self.0.lock().await;
if *guard != 0 {
*guard -= 1;
true
} else {
false
}
}
}