Function run

Source
pub fn run<R, F, T>(py: Python<'_>, fut: F) -> PyResult<T>
where R: Runtime + ContextExt, F: Future<Output = PyResult<T>> + Send + 'static, T: Send + Sync + 'static,
Expand description

Run the event loop until the given Future completes

§Arguments

  • py - The current PyO3 GIL guard
  • fut - The future to drive to completion

§Examples

fn main() {
    Python::with_gil(|py| {
        pyo3_async_runtimes::generic::run::<MyCustomRuntime, _, _>(py, async move {
            custom_sleep(Duration::from_secs(1)).await;
            Ok(())
        })
        .map_err(|e| {
            e.print_and_set_sys_last_vars(py);
        })
        .unwrap();
    })
}