Skip to main content

Task

Struct Task 

Source
pub struct Task { /* private fields */ }
Expand description

A task wrapping an async future with a unique ID.

Implementations§

Source§

impl Task

Source

pub fn new(future: impl Future<Output = ()> + 'static) -> Self

Creates a new task from an async future.

Examples found in repository?
examples/basic_spawn.rs (lines 5-7)
3fn main() {
4    let mut executor = Executor::new().unwrap();
5    executor.spawn(Task::new(async {
6        println!("Hello from an async task!");
7    }));
8    executor.run();
9}
More examples
Hide additional examples
examples/custom_id_timer.rs (lines 12-18)
5fn main() {
6    let executor = Arc::new(Mutex::new(Executor::new().unwrap()));
7    let timer_data = executor.lock().unwrap().timer_data();
8    let start = std::time::Instant::now();
9
10    {
11        let mut exec = executor.lock().unwrap();
12        exec.spawn(Task::new(async move {
13            println!("Starting timer at {:?}", start.elapsed());
14            std::io::Write::flush(&mut std::io::stdout()).unwrap();
15            let timer = TimerFuture::new(Duration::from_millis(500), timer_data);
16            timer.await;
17            println!("Timer fired at {:?}", start.elapsed());
18        }));
19    }
20
21    executor.lock().unwrap().run();
22}

Auto Trait Implementations§

§

impl Freeze for Task

§

impl !RefUnwindSafe for Task

§

impl !Send for Task

§

impl !Sync for Task

§

impl Unpin for Task

§

impl UnsafeUnpin for Task

§

impl !UnwindSafe for Task

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.