Async task switching for cooperative multitasking in single threaded environments.
This library provides tools to dynamically manage group of tasks in single threaded or embedded
environments. Note than this is not an operating system but can serve as a simple replacement
where you don't need context switches, for example on embedded applications.
Tasks use async/await mechanisms of Rust and it's programmer job to insert switching
points into them. Luckily this crate provides Yield
utility for this as well as
handling busy waits. Primary scheduler (Wheel
) can dynamically spawn, suspend, resume
or cancel tasks managed by round robin algorithm.
Crate by default uses std library (feature std
) but also can be configured
as #![no_std]
with alloc
crate, this disables some features in util
module.
Simple program that reads data from sensor and processes it. ```rust use juggle::*; use alloc::collections::VecDeque; use core::cell::RefCell;
async fn collecttemperature(queue: &RefCell
async fn waitfortimer(id: IdNum,queue: &RefCell
fn main(){ let queue = &RefCell::new(VecDeque::new()); let wheel = Wheel::new(); let handle = wheel.handle(); // handle to manage tasks, can be cloned inside this thread
let temp_id = handle.spawn(SpawnParams::default(),
collect_temperature(queue,handle.clone()));
handle.spawn(SpawnParams::default(),
wait_for_timer(temp_id.unwrap(),queue,handle.clone()));
// execute tasks
smol::block_on(wheel).unwrap(); // or any other utility to block on future.
} ```