memkit-async 0.2.0-beta.1

Async-aware memory allocators for memkit
//! Backpressure policies for async allocators.

use std::time::Duration;

/// Backpressure policy for when allocation would block.
#[derive(Debug, Clone)]
pub enum MkBackpressure {
    /// Wait indefinitely for memory to become available.
    Wait,
    
    /// Fail immediately if no memory available.
    Fail,
    
    /// Wait up to a timeout, then fail.
    Timeout(Duration),
    
    /// Evict least-recently-used items to make room.
    Evict,
}

impl Default for MkBackpressure {
    fn default() -> Self {
        Self::Wait
    }
}

impl MkBackpressure {
    /// Create a timeout policy.
    pub fn timeout(duration: Duration) -> Self {
        Self::Timeout(duration)
    }

    /// Create a timeout policy from milliseconds.
    pub fn timeout_ms(ms: u64) -> Self {
        Self::Timeout(Duration::from_millis(ms))
    }
}