pub struct Runtime { /* private fields */ }Expand description
Automation runtime that manages concurrent task lifecycles.
The runtime owns a CancellationToken shared by all spawned tasks
and collects their JoinHandles for graceful shutdown. It does not
own specific business dependencies – those are passed when spawning
individual loops.
Implementations§
Source§impl Runtime
impl Runtime
Sourcepub fn cancel_token(&self) -> CancellationToken
pub fn cancel_token(&self) -> CancellationToken
Return a clone of the cancellation token for passing to tasks.
Sourcepub fn spawn<F>(&mut self, name: impl Into<String>, future: F)
pub fn spawn<F>(&mut self, name: impl Into<String>, future: F)
Spawn an automation task with a descriptive name.
The task’s JoinHandle is tracked for shutdown. The task should
check CancellationToken::is_cancelled() in its loop to exit
gracefully when shutdown is initiated.
Sourcepub fn task_count(&self) -> usize
pub fn task_count(&self) -> usize
Return the number of spawned tasks.
Sourcepub async fn shutdown(&mut self)
pub async fn shutdown(&mut self)
Initiate graceful shutdown.
- Cancels the token, signaling all tasks to stop.
- Awaits all
JoinHandles with a 30-second timeout. - If timeout is exceeded, logs a warning (caller decides whether to force-exit).
Sourcepub async fn run_until_shutdown(self)
pub async fn run_until_shutdown(self)
Block until a shutdown signal is received, then gracefully stop all tasks.
This is the typical entry point for the tuitbot run command:
- Spawn all tasks.
- Call
run_until_shutdown()to block until Ctrl+C / SIGTERM. - All tasks are stopped and awaited.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Runtime
impl RefUnwindSafe for Runtime
impl Send for Runtime
impl Sync for Runtime
impl Unpin for Runtime
impl UnsafeUnpin for Runtime
impl UnwindSafe for Runtime
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more