pub struct JoinMap<K, V> { /* private fields */ }Expand description
A collection of keyed tasks spawned on a Tokio runtime. Hacky implementation of a join set that allows for a key to be associated with each task by having the task return a tuple of (key, value).
Implementations§
Source§impl<K, V> JoinMap<K, V>
impl<K, V> JoinMap<K, V>
Sourcepub fn spawn<F>(&mut self, key: K, future: F)
pub fn spawn<F>(&mut self, key: K, future: F)
Spawns a task onto the Tokio runtime that will execute the given future ONLY IF there is not already a task in the set with the same key.
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Returns true if the JoinSet contains a task for the given key.
Sourcepub async fn join_next(&mut self) -> Option<Result<(K, V), JoinError>>
pub async fn join_next(&mut self) -> Option<Result<(K, V), 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 poll_join_next(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Option<Result<(K, V), JoinError>>>
pub fn poll_join_next( &mut self, cx: &mut Context<'_>, ) -> Poll<Option<Result<(K, V), JoinError>>>
Polls for one of the tasks in the set to complete.
If this returns Poll::Ready(Some(_)), then the task that completed is removed from the
set.
When the method returns Poll::Pending, the Waker in the provided Context is scheduled
to receive a wakeup when a task in the JoinSet completes. Note that on multiple calls to
poll_join_next, only the Waker from the Context passed to the most recent call is
scheduled to receive a wakeup.
§Returns
This function returns:
Poll::Pendingif theJoinSetis not empty but there is no task whose output is available right now.Poll::Ready(Some(Ok(value)))if one of the tasks in thisJoinSethas completed. Thevalueis the return value of one of the tasks that completed.Poll::Ready(Some(Err(err)))if one of the tasks in thisJoinSethas panicked or been aborted. Theerris theJoinErrorfrom the panicked/aborted task.Poll::Ready(None)if theJoinSetis empty.
Note that this method may return Poll::Pending even if one of the tasks has completed.
This can happen if the [coop budget] is reached.