JoinHandle

Struct JoinHandle 

Source
pub struct JoinHandle<T> { /* private fields */ }
Expand description

Task handle for spawned futures

Implementations§

Source§

impl<T> JoinHandle<T>

Source

pub async fn await_result(self) -> Option<T>

Wait for the task to complete and return its result

Examples found in repository?
examples/parallel_tasks.rs (line 24)
4fn main() {
5    let rt = Runtime::new();
6
7    rt.block_on(async move {
8        println!("Spawning 100 concurrent tasks...");
9
10        let mut handles = vec![];
11
12        for i in 0..100 {
13            let handle = rt.spawn_with_handle(async move {
14                avx_async::sleep(Duration::from_millis(10)).await;
15                i * i
16            });
17            handles.push(handle);
18        }
19
20        println!("Waiting for all tasks to complete...");
21
22        let mut sum = 0;
23        for handle in handles {
24            if let Some(result) = handle.await_result().await {
25                sum += result;
26            }
27        }
28
29        println!("Sum of squares from 0 to 99: {}", sum);
30        println!("Active tasks: {}", rt.task_count());
31    });
32}

Auto Trait Implementations§

§

impl<T> Freeze for JoinHandle<T>

§

impl<T> RefUnwindSafe for JoinHandle<T>

§

impl<T> Send for JoinHandle<T>
where T: Send,

§

impl<T> Sync for JoinHandle<T>
where T: Send,

§

impl<T> Unpin for JoinHandle<T>

§

impl<T> UnwindSafe for JoinHandle<T>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.