dagrs 0.8.0

Dagrs follows the concept of Flow-based Programming and is suitable for the execution of multiple tasks with graph-like dependencies. Dagrs has the characteristics of high performance and asynchronous execution. It provides users with a convenient programming interface.
Documentation
use std::sync::atomic::AtomicUsize;

use super::NodeId;

/// IDAllocator for Node.
struct IDAllocator {
    id: AtomicUsize,
}

impl IDAllocator {
    fn alloc(&self) -> NodeId {
        let origin = self.id.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
        if origin > self.id.load(std::sync::atomic::Ordering::Relaxed) {
            panic!("Too many tasks.")
        } else {
            NodeId(origin)
        }
    }
}

/// The global task uniquely identifies an instance of the allocator.
static ID_ALLOCATOR: IDAllocator = IDAllocator {
    id: AtomicUsize::new(1),
};

/// Assign node's id.
pub(crate) fn alloc_id() -> NodeId {
    ID_ALLOCATOR.alloc()
}