Crates.io | tpx |
lib.rs | tpx |
version | 0.1.0 |
source | src |
created_at | 2023-07-17 01:30:06.428565 |
updated_at | 2023-07-17 01:30:06.428565 |
description | Task scheduler |
homepage | https://github.com/marek-miller/tpx |
repository | https://github.com/marek-miller/tpx.git |
max_upload_size | |
id | 918087 |
size | 10,832 |
Schedule and run coroutines.
use std::{thread::sleep, time::Duration};
use tpx::{continue_with, Ctn::DONE, Executor};
fn main() {
let exec = Executor::init();
// Spawn 3 tasks: each task schedules its own continuation
for i in 0..3 {
exec.spawn(move || {
println!("Hello from task {i}");
// Some data to passed to the continuation
let j = i * 3;
sleep(Duration::from_millis(123));
// Yield to the executor.
continue_with(move || {
println!("Hello from continuation {i}: Result: {j}");
DONE
})
});
}
// TODO: block on the executor until all tasks are done.
sleep(Duration::from_secs(3));
}