Skip to main content

reifydb_core/interface/catalog/
task.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 ReifyDB
3
4use std::{
5	fmt,
6	sync::atomic::{AtomicU64, Ordering},
7};
8
9/// Unique identifier for a scheduled task
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
11pub struct TaskId(u64);
12
13impl TaskId {
14	/// Generate a new unique task ID
15	pub fn new() -> Self {
16		static COUNTER: AtomicU64 = AtomicU64::new(1);
17		Self(COUNTER.fetch_add(1, Ordering::Relaxed))
18	}
19}
20
21impl Default for TaskId {
22	fn default() -> Self {
23		Self::new()
24	}
25}
26
27impl fmt::Display for TaskId {
28	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29		write!(f, "task-{}", self.0)
30	}
31}