Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic Rust interfaces #20

Open
gi0baro opened this issue Jan 21, 2025 · 0 comments
Open

Add basic Rust interfaces #20

gi0baro opened this issue Jan 21, 2025 · 0 comments
Labels
rust Issues/PRs related to Rust interfaces

Comments

@gi0baro
Copy link
Owner

gi0baro commented Jan 21, 2025

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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rust Issues/PRs related to Rust interfaces
Projects
None yet
Development

No branches or pull requests

1 participant