Struct holochain::prelude::kitsune_p2p::dependencies::kitsune_p2p_types::dependencies::lair_keystore_api::dependencies::tokio::task::JoinSet
source · pub struct JoinSet<T> { /* private fields */ }
Expand description
A collection of tasks spawned on a Tokio runtime.
A JoinSet
can be used to await the completion of some or all of the tasks
in the set. The set is not ordered, and the tasks will be returned in the
order they complete.
All of the tasks must have the same return type T
.
When the JoinSet
is dropped, all tasks in the JoinSet
are immediately aborted.
Examples
Spawn multiple tasks and wait for them.
use tokio::task::JoinSet;
#[tokio::main]
async fn main() {
let mut set = JoinSet::new();
for i in 0..10 {
set.spawn(async move { i });
}
let mut seen = [false; 10];
while let Some(res) = set.join_next().await {
let idx = res.unwrap();
seen[idx] = true;
}
for i in 0..10 {
assert!(seen[i]);
}
}
Implementations
sourceimpl<T> JoinSet<T>where
T: 'static,
impl<T> JoinSet<T>where
T: 'static,
sourcepub fn spawn<F>(&mut self, task: F) -> AbortHandlewhere
F: Future<Output = T> + 'static + Send,
T: Send,
pub fn spawn<F>(&mut self, task: F) -> AbortHandlewhere
F: Future<Output = T> + 'static + Send,
T: Send,
Spawn the provided task on the JoinSet
, returning an AbortHandle
that can be used to remotely cancel the task.
Panics
This method panics if called outside of a Tokio runtime.
sourcepub fn spawn_on<F>(&mut self, task: F, handle: &Handle) -> AbortHandlewhere
F: Future<Output = T> + 'static + Send,
T: Send,
pub fn spawn_on<F>(&mut self, task: F, handle: &Handle) -> AbortHandlewhere
F: Future<Output = T> + 'static + Send,
T: Send,
Spawn the provided task on the provided runtime and store it in this
JoinSet
returning an AbortHandle
that can be used to remotely
cancel the task.
sourcepub fn spawn_local<F>(&mut self, task: F) -> AbortHandlewhere
F: Future<Output = T> + 'static,
pub fn spawn_local<F>(&mut self, task: F) -> AbortHandlewhere
F: Future<Output = T> + 'static,
Spawn the provided task on the current LocalSet
and store it in this
JoinSet
, returning an AbortHandle
that can be used to remotely
cancel the task.
Panics
This method panics if it is called outside of a LocalSet
.
sourcepub fn spawn_local_on<F>(&mut self, task: F, local_set: &LocalSet) -> AbortHandlewhere
F: Future<Output = T> + 'static,
pub fn spawn_local_on<F>(&mut self, task: F, local_set: &LocalSet) -> AbortHandlewhere
F: Future<Output = T> + 'static,
Spawn the provided task on the provided LocalSet
and store it in
this JoinSet
, returning an AbortHandle
that can be used to
remotely cancel the task.
sourcepub async fn join_next(
&mut self
) -> impl Future<Output = Option<Result<T, JoinError>>>
pub async fn join_next(
&mut self
) -> impl Future<Output = Option<Result<T, JoinError>>>
Waits until one of the tasks in the set completes and returns its output.
Returns None
if the set is empty.
Cancel Safety
This method is cancel safe. If join_next
is used as the event in a tokio::select!
statement and some other branch completes first, it is guaranteed that no tasks were
removed from this JoinSet
.
sourcepub fn abort_all(&mut self)
pub fn abort_all(&mut self)
Aborts all tasks on this JoinSet
.
This does not remove the tasks from the JoinSet
. To wait for the tasks to complete
cancellation, you should call join_next
in a loop until the JoinSet
is empty.
sourcepub fn detach_all(&mut self)
pub fn detach_all(&mut self)
Removes all tasks from this JoinSet
without aborting them.
The tasks removed by this call will continue to run in the background even if the JoinSet
is dropped.
Trait Implementations
Auto Trait Implementations
impl<T> !RefUnwindSafe for JoinSet<T>
impl<T> Send for JoinSet<T>where
T: Send,
impl<T> Sync for JoinSet<T>where
T: Send,
impl<T> Unpin for JoinSet<T>
impl<T> !UnwindSafe for JoinSet<T>
Blanket Implementations
impl<T> Any for Twhere
T: Any + ?Sized,
impl<T> Any for Twhere
T: Any + ?Sized,
fn type_id_compat(&self) -> TypeId
fn type_id_compat(&self) -> TypeId
impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
type ArchivedMetadata = ()
type ArchivedMetadata = ()
fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
impl<T> FutureExt for T
impl<T> FutureExt for T
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
sourcefn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
sourcefn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
impl<T> Pointable for T
impl<T> Pointable for T
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read morefn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.