Function pyo3_asyncio::generic::future_into_py [−][src]
pub fn future_into_py<R, F>(py: Python<'_>, fut: F) -> PyResult<&PyAny> where
R: Runtime,
F: Future<Output = PyResult<PyObject>> + Send + 'static,
Expand description
Convert a Rust Future into a Python awaitable with a generic runtime
Arguments
py
- The current PyO3 GIL guardfut
- The Rust future to be converted
Examples
use std::time::Duration; use pyo3::prelude::*; /// Awaitable sleep function #[pyfunction] fn sleep_for<'p>(py: Python<'p>, secs: &'p PyAny) -> PyResult<&'p PyAny> { let secs = secs.extract()?; pyo3_asyncio::generic::future_into_py::<MyCustomRuntime, _>(py, async move { MyCustomRuntime::sleep(Duration::from_secs(secs)).await; Python::with_gil(|py| Ok(py.None())) }) }