pub struct Task { /* private fields */ }Expand description
A task wrapping an async future with a unique ID.
Implementations§
Source§impl Task
impl Task
Sourcepub fn new(future: impl Future<Output = ()> + 'static) -> Self
pub fn new(future: impl Future<Output = ()> + 'static) -> Self
Creates a new task from an async future.
Examples found in repository?
More 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> 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
Mutably borrows from an owned value. Read more