pub struct OperationContext { /* private fields */ }Expand description
Cancellation, deadline, and task-class metadata for one bounded operation.
An operation is not a lifecycle owner and does not create a child
TaskGroup. Tasks spawned for the operation remain registered with a
fixed component owner while this context supplies operation-local
cancellation and bounded join semantics.
Implementations§
Source§impl OperationContext
impl OperationContext
Sourcepub async fn wait_with_policy(
&self,
owner: &TaskGroup,
policy: OperationWaitPolicy,
) -> RuntimeResult<OperationWaitOutcome>
pub async fn wait_with_policy( &self, owner: &TaskGroup, policy: OperationWaitPolicy, ) -> RuntimeResult<OperationWaitOutcome>
Closes operation admission and asynchronously waits using explicit deadlines.
Tasks unfinished at the graceful deadline are asked to abort. The second deadline bounds confirmation of future destruction and owner settlement. An unconfirmed outcome leaves those tasks visible to the owner’s report. Deadlines bound cooperative waiting; blocked executor threads can delay polling and this method does not promise a hard wall-clock return time.
§Errors
Returns an error without closing admission if owner is not this
operation’s bound component owner.
Sourcepub fn new(deadline: Instant, task_kind: TaskKind) -> Self
pub fn new(deadline: Instant, task_kind: TaskKind) -> Self
Creates an operation with an absolute deadline.
Sourcepub fn without_deadline(task_kind: TaskKind) -> Self
pub fn without_deadline(task_kind: TaskKind) -> Self
Creates an operation that remains active until explicitly cancelled.
Sourcepub fn cancellation_token(&self) -> CancellationToken
pub fn cancellation_token(&self) -> CancellationToken
Returns the operation-local cancellation token.
Sourcepub fn deadline(&self) -> Option<Instant>
pub fn deadline(&self) -> Option<Instant>
Returns the absolute deadline, when one was configured.
Sourcepub fn task_kind(&self) -> TaskKind
pub fn task_kind(&self) -> TaskKind
Returns the task classification applied to operation tasks.
Sourcepub fn with_task_kind(&self, task_kind: TaskKind) -> Self
pub fn with_task_kind(&self, task_kind: TaskKind) -> Self
Returns a view of this operation with a different task classification.
Cancellation, deadline, owner binding, and active-task tracking remain shared with the original context.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Returns whether cancellation has been requested.
Sourcepub fn close_admission(&self)
pub fn close_admission(&self)
Closes task admission without cancelling tasks that were already accepted.
Sourcepub fn active_task_count(&self) -> usize
pub fn active_task_count(&self) -> usize
Returns the number of operation tasks that have not completed.
Sourcepub fn outcomes(&self) -> [(OperationOutcome, u64); 6]
pub fn outcomes(&self) -> [(OperationOutcome, u64); 6]
Reads counters without retaining individual task history.
Counters share this operation’s lifetime and are individually atomic; completions can occur between fields in this snapshot.
Sourcepub fn set_outcome_observer(
&self,
observer: Arc<dyn OperationOutcomeObserver>,
) -> RuntimeResult<()>
pub fn set_outcome_observer( &self, observer: Arc<dyn OperationOutcomeObserver>, ) -> RuntimeResult<()>
Binds an observer before the first submission attempt.
§Errors
Returns an error after owner binding or an earlier observer installation.
Sourcepub async fn cancel_and_wait(
&self,
owner: &TaskGroup,
timeout: Duration,
) -> RuntimeResult<bool>
pub async fn cancel_and_wait( &self, owner: &TaskGroup, timeout: Duration, ) -> RuntimeResult<bool>
Cancels this operation and waits for all tasks registered with owner.
Returns true when every task completed before the shared timeout.
Tasks still running at the deadline are aborted and awaited for a
confirmation window of at most one second beyond it. false does not
distinguish a confirmed abort from work whose destruction is still
unconfirmed. Use Self::wait_with_policy after Self::cancel for
explicit deadlines and completion evidence. Timers require the runtime
to make progress; they are not a hard wall-clock return guarantee.
§Errors
Returns an error when owner differs from the component owner used to
spawn the operation.
Sourcepub async fn cancel_and_wait_until(
&self,
owner: &TaskGroup,
deadline: ShutdownDeadline,
) -> RuntimeResult<bool>
pub async fn cancel_and_wait_until( &self, owner: &TaskGroup, deadline: ShutdownDeadline, ) -> RuntimeResult<bool>
Cancels this operation and bounds its asynchronous wait by deadline.
Behaves like Self::wait_until after requesting cancellation.
§Errors
Returns an error when owner differs from the component owner used to
spawn the operation.
Sourcepub async fn wait(
&self,
owner: &TaskGroup,
timeout: Duration,
) -> RuntimeResult<bool>
pub async fn wait( &self, owner: &TaskGroup, timeout: Duration, ) -> RuntimeResult<bool>
Waits until no operation task is active and owner has settled every
one, without requesting cancellation. Tasks still running at the
deadline are aborted and awaited for a confirmation window of at most
one second, so the call can return up to one second after timeout.
Tasks accepted during the wait are waited for too; close admission
first when new tasks may still be submitted. Returns true when every
task finished before the deadline; owner then no longer lists any of
them. false does not confirm destruction. Use Self::wait_until to
avoid an extra confirmation allowance, or Self::wait_with_policy
to distinguish confirmed aborts from unconfirmed work.
§Errors
Returns an error when owner differs from the component owner used to
spawn the operation.
Sourcepub async fn wait_until(
&self,
owner: &TaskGroup,
deadline: ShutdownDeadline,
) -> RuntimeResult<bool>
pub async fn wait_until( &self, owner: &TaskGroup, deadline: ShutdownDeadline, ) -> RuntimeResult<bool>
Waits for this operation’s tasks with no allowance beyond deadline.
Tasks still running at the deadline are asked to abort and the call
returns false at once, without confirming that their futures were
dropped. They stay registered with owner until they are, so the
owner’s shutdown report accounts for any that remain. This matches
TaskGroup::shutdown_until, which also does not extend its deadline.
Runtime starvation or synchronous destructors can delay timer polling.
§Errors
Returns an error when owner differs from the component owner used to
spawn the operation.