Skip to content

Add basic Rust interfaces #20

@gi0baro

Description

@gi0baro

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    rustIssues/PRs related to Rust interfaces

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions