pub struct TurnScope { /* private fields */ }Expand description
One turn’s cancellable scope. Construct once per SubmitPrompt;
abandon (drop) at the end of the turn.
Implementations§
Source§impl TurnScope
impl TurnScope
pub fn new(id: TurnId) -> Self
pub fn id(&self) -> TurnId
Sourcepub fn token(&self) -> CancellationToken
pub fn token(&self) -> CancellationToken
Clone the scope’s token. Hand this to child tasks so they can participate in cooperative cancellation.
Sourcepub fn background_token(&self) -> CancellationToken
pub fn background_token(&self) -> CancellationToken
Clone the scope’s background-request token (Ctrl+B). Tools that can detach a running child select on this instead of killing it.
Sourcepub fn background(&self)
pub fn background(&self)
Signal “background the running work” to every child task that listens.
Sourcepub fn spawn<Fut>(&mut self, fut: Fut) -> AbortHandle
pub fn spawn<Fut>(&mut self, fut: Fut) -> AbortHandle
Spawn a child task under this scope. The returned handle is
retained inside the scope’s JoinSet — callers don’t need to
keep it. Cancellation of the scope aborts the task at its next
await.
Sourcepub fn cancel(&self)
pub fn cancel(&self)
Signal cancellation to every child task. Returns immediately —
callers drain the JoinSet separately via drain_completed.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
True iff the scope has been cancelled.
Sourcepub async fn join_next(&mut self) -> Option<Result<(), JoinError>>
pub async fn join_next(&mut self) -> Option<Result<(), JoinError>>
Join one task if any has completed. Returns None immediately
when the set is empty or nothing is ready. Intended for the
main loop’s per-tick bookkeeping — not a blocking drain.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
True iff no child task is currently running inside this scope.
The main loop uses this after a cancel() to decide when to
transition from TurnState::Cancelling back to Idle.
Sourcepub fn drain_completed(&mut self)
pub fn drain_completed(&mut self)
Drain any already-completed tasks from the JoinSet without
blocking. JoinSet::is_empty only flips to true after finished
tasks are explicitly harvested via join_next; without this,
EffectRunner::reap_empty_scopes would see finished-but-not-
joined scopes as “still busy” and never reap them. F12.
pub fn len(&self) -> usize
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for TurnScope
impl !UnwindSafe for TurnScope
impl Freeze for TurnScope
impl Send for TurnScope
impl Sync for TurnScope
impl Unpin for TurnScope
impl UnsafeUnpin for TurnScope
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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>
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>
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