Basics:
- scheduling Python callbacks (mimic
call_soon)
- scheduling Python callbacks with specific delay (mimic
call_later)
Nice to have:
- Future wrapping (eg: create a special subclass of
asyncio.Future that allows to set a result from Rust and react to cancellations
Having pyo3 and a Py<EventLoop> ref (could be stored in Rust) should be enough:
fn my_rust_fn(event_loop: &Py<EventLoop>, callback: PyObject) {
let arg = "foo";
let args: PyObject = Python::with_gil(|py| (arg,).into_py_any(py).unwrap());
// call soon
event_loop.schedule(callback, args);
// call later (5s)
event_loop.schedule_later(std::time::Duration::new(5, 0), callback, args);
}
Basics:
call_soon)call_later)Nice to have:
asyncio.Futurethat allows to set a result from Rust and react to cancellationsHaving
pyo3and aPy<EventLoop>ref (could be stored in Rust) should be enough: