zephyr::kio

Function spawn_local

Source
pub fn spawn_local<F>(future: F, name: &'static CStr) -> JoinHandle<F>
where F: Future + 'static, F::Output: Send + 'static,
Expand description

Run an async future on the current worker thread.

Arrange to have the given future run on the current worker thread. The resulting JoinHandle has join and join_async methods that can be used to wait for the given thread.

By constraining the spawn to the current worker, this function is able to remove the Send constraint from the future (and its return type), allowing tasks to share data using lighter-weight mechanimsms, such as Rc and Rc<RefCell<T>>, or &'static RefCell<T>.

To be able to use tasks running on different workers, sharing must be done with types such as Arc, and Arc<Mutex<T>>, or &'static Mutex<T>.

It is important, when using RefCell, that a borrow from the cell not be carried across an await boundary, or RefCell’s runtime multi-borrow check can cause a panic.

§Panics

If this is called other than from a worker task running on a work thread, it will panic.