pub enum OrphanPolicy {
Enforced,
Permissive,
}Expand description
Defines the runtime’s structured concurrency policy.
This policy dictates what happens when a parent task exits before its child tasks have completed.
The default policy is OrphanPolicy::Enforced, which guarantees that
children are cancelled when their parent exits. This global policy can be
set to OrphanPolicy::Permissive to allow children to outlive their parents.
Note on Detached Tasks:
This policy controls the global behavior for parent-child relationships. It is separate from spawning an individually “detached” task.
The idiomatic way to spawn a task that is not attached to the current
parent is to use TaskOpts::BACKGROUND_TASK. This option attaches the
new task directly to the ROOT_NODE of the task tree, allowing it to
outlive its spawner regardless of the OrphanPolicy.
§Example
use ringolo::TaskOpts;
ringolo::spawn_builder()
.with_opts(TaskOpts::BACKGROUND_TASK)
.spawn(async {
// ... background work ...
});Variants§
Enforced
All children of a task are cancelled on exit. The program is not allowed
to create orphans. This leads to better performance because we prevent many
synchronous parent swapping operations and avoid child adoption by the
ORPHAN_ROOT_NODE.
Permissive
Children are allowed to outlive their parents. If a parent terminates before
it’s children, all of the children are adopted by the ORPHAN_ROOT_NODE and
become orphans. This flexibility comes at a cost, with synchronous parent
swapping operations and child adoption.
Trait Implementations§
Source§impl Clone for OrphanPolicy
impl Clone for OrphanPolicy
Source§fn clone(&self) -> OrphanPolicy
fn clone(&self) -> OrphanPolicy
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for OrphanPolicy
impl Debug for OrphanPolicy
Source§impl Default for OrphanPolicy
impl Default for OrphanPolicy
Source§fn default() -> OrphanPolicy
fn default() -> OrphanPolicy
Source§impl PartialEq for OrphanPolicy
impl PartialEq for OrphanPolicy
impl Copy for OrphanPolicy
impl Eq for OrphanPolicy
impl StructuralPartialEq for OrphanPolicy
Auto Trait Implementations§
impl Freeze for OrphanPolicy
impl RefUnwindSafe for OrphanPolicy
impl Send for OrphanPolicy
impl Sync for OrphanPolicy
impl Unpin for OrphanPolicy
impl UnwindSafe for OrphanPolicy
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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