| 117 | } |
| 118 | |
| 119 | async fn await_async_iter_value(coro: Py<PyAny>) -> FlowResult<Option<Json>> { |
| 120 | let future = Python::attach(|py| { |
| 121 | pyo3_async_runtimes::tokio::into_future(coro.into_bound(py)) |
| 122 | .map_err(|e| FlowError::Internal(e.to_string())) |
| 123 | })?; |
| 124 | |
| 125 | match future.await { |
| 126 | Ok(result) => Python::attach(|py| { |
| 127 | py_to_json(result.bind(py)) |
| 128 | .map(Some) |
| 129 | .map_err(|e| FlowError::Internal(e.to_string())) |
| 130 | }), |
| 131 | Err(error) => Python::attach(|py| { |
| 132 | if error.is_instance_of::<pyo3::exceptions::PyStopAsyncIteration>(py) { |
| 133 | Ok(None) |
| 134 | } else { |
| 135 | Err(FlowError::Internal(error.to_string())) |
| 136 | } |
| 137 | }), |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | async fn forward_async_iter( |
| 142 | async_iter: Arc<Py<PyAny>>, |