Skip to main content

OperationContext

Struct OperationContext 

Source
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

Source

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.

Source

pub fn new(deadline: Instant, task_kind: TaskKind) -> Self

Creates an operation with an absolute deadline.

Source

pub fn without_deadline(task_kind: TaskKind) -> Self

Creates an operation that remains active until explicitly cancelled.

Source

pub fn cancellation_token(&self) -> CancellationToken

Returns the operation-local cancellation token.

Source

pub fn deadline(&self) -> Option<Instant>

Returns the absolute deadline, when one was configured.

Source

pub fn task_kind(&self) -> TaskKind

Returns the task classification applied to operation tasks.

Source

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.

Source

pub fn is_cancelled(&self) -> bool

Returns whether cancellation has been requested.

Source

pub fn cancel(&self)

Requests cancellation for every task in this operation.

Source

pub fn close_admission(&self)

Closes task admission without cancelling tasks that were already accepted.

Source

pub fn active_task_count(&self) -> usize

Returns the number of operation tasks that have not completed.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for OperationContext

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OperationContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more