pub struct Executor { /* private fields */ }Expand description
The main executor that runs async tasks and handles I/O events.
Implementations§
Source§impl Executor
impl Executor
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Creates a new executor with default ID generator.
Examples found in repository?
More examples
examples/custom_id_timer.rs (line 6)
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}Sourcepub fn spawn(&mut self, task: Task)
pub fn spawn(&mut self, task: Task)
Spawns a new task with 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}Sourcepub fn register_timer(&mut self, deadline: Instant, waker: Waker)
pub fn register_timer(&mut self, deadline: Instant, waker: Waker)
Registers a timer to wake at the given deadline.
Sourcepub fn timer_data(&self) -> Arc<Mutex<TimerData>>
pub fn timer_data(&self) -> Arc<Mutex<TimerData>>
Gets the timer data for creating timers.
Examples found in repository?
examples/custom_id_timer.rs (line 7)
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}Sourcepub fn run(&mut self)
pub fn run(&mut self)
Runs the executor event loop until all tasks complete.
Examples found in repository?
More examples
examples/custom_id_timer.rs (line 21)
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 Executor
impl !RefUnwindSafe for Executor
impl !Send for Executor
impl !Sync for Executor
impl Unpin for Executor
impl UnsafeUnpin for Executor
impl !UnwindSafe for Executor
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