pub struct TrackedTaskGroup { /* private fields */ }Expand description
A group of spawned tasks whose lifecycle is tracked.
When finalize is called, the group
joins each handle with the configured grace period and reports any
tasks still running as leaks.
§Example
use dev_async::tasks::TrackedTaskGroup;
use std::time::Duration;
let mut group = TrackedTaskGroup::new("workers");
group.spawn(async { tokio::time::sleep(Duration::from_millis(5)).await; });
group.spawn(async { tokio::time::sleep(Duration::from_millis(5)).await; });
let check = group.finalize(Duration::from_millis(50)).await;
assert!(check.has_tag("async"));Implementations§
Source§impl TrackedTaskGroup
impl TrackedTaskGroup
Sourcepub fn spawn<F>(&mut self, fut: F)
pub fn spawn<F>(&mut self, fut: F)
Spawn a future and track its handle.
The future MUST resolve to (). If you need a result, capture
it via shared state (e.g. tokio::sync::oneshot::Sender).
Sourcepub fn spawned_count(&self) -> usize
pub fn spawned_count(&self) -> usize
How many tasks have been spawned through this group so far.
Sourcepub async fn finalize(self, grace: Duration) -> CheckResult
pub async fn finalize(self, grace: Duration) -> CheckResult
Join all tracked tasks with a per-task grace period and emit a
CheckResult.
Verdicts:
- All tasks completed cleanly ->
Pass. - One or more tasks panicked ->
Fail (Critical)withtask_panickedtag. - One or more tasks did not finish in time (leak suspected) ->
Fail (Error)withtask_leaktag.
Auto Trait Implementations§
impl Freeze for TrackedTaskGroup
impl RefUnwindSafe for TrackedTaskGroup
impl Send for TrackedTaskGroup
impl Sync for TrackedTaskGroup
impl Unpin for TrackedTaskGroup
impl UnsafeUnpin for TrackedTaskGroup
impl UnwindSafe for TrackedTaskGroup
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