Function pyo3_asyncio::tokio::cancellable_future_into_py_with_loop [−][src]
pub fn cancellable_future_into_py_with_loop<F>(
event_loop: &PyAny,
fut: F
) -> PyResult<&PyAny> where
F: Future<Output = PyResult<PyObject>> + Send + 'static, 👎 Deprecated since 0.15.0:
Use pyo3_asyncio::tokio::future_into_py_with_locals instead
Expand description
Convert a Rust Future into a Python awaitable
This function was deprecated in favor of future_into_py_with_locals in v0.15 because
it became the default behaviour. In v0.15, any calls to this function should be
replaced with future_into_py_with_locals.
This function will be removed in v0.16
Arguments
event_loop- The Python event loop that the awaitable should be attached tofut- 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::tokio::cancellable_future_into_py_with_loop(
pyo3_asyncio::tokio::get_current_loop(py)?,
async move {
tokio::time::sleep(Duration::from_secs(secs)).await;
Ok(Python::with_gil(|py| py.None()))
}
)
}