pub struct TaskPool<K, T>where
T: Send + 'static,{ /* private fields */ }Expand description
A keyed pool of async tasks with lifecycle status tracking.
Each key maps to at most one running task. Spawning under an existing key
aborts the previous task. Status transitions (Pending, Resolved,
Error, Aborted) are reported via the on_status_change callback
provided at construction time.
§Type parameters
Implementations§
Source§impl<K, T> TaskPool<K, T>
impl<K, T> TaskPool<K, T>
Sourcepub fn new(
rt: Handle,
on_status_change: impl Fn(&K, TaskStatus<T>) + Send + Sync + 'static,
) -> Self
pub fn new( rt: Handle, on_status_change: impl Fn(&K, TaskStatus<T>) + Send + Sync + 'static, ) -> Self
Create a new task pool.
on_status_change is called whenever a task’s status transitions
(Pending, Resolved, Error, Aborted). The caller provides a closure
that updates state (e.g., a HashMap in their DomainData).
Sourcepub fn spawn<F, Fut>(&self, key: K, f: F)
pub fn spawn<F, Fut>(&self, key: K, f: F)
Spawn a task under the given key.
Aborts any previous task with the same key. Sets status to Pending,
then Resolved on completion. If the task panics, the status remains
Pending (the panic is caught by tokio but the callback is not reached).
Trait Implementations§
Auto Trait Implementations§
impl<K, T> Freeze for TaskPool<K, T>
impl<K, T> !RefUnwindSafe for TaskPool<K, T>
impl<K, T> Send for TaskPool<K, T>where
K: Send,
impl<K, T> Sync for TaskPool<K, T>where
K: Send,
impl<K, T> Unpin for TaskPool<K, T>
impl<K, T> UnsafeUnpin for TaskPool<K, T>
impl<K, T> !UnwindSafe for TaskPool<K, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more