Returns an `asyncio.Future` that resolves to the next `AgentEvent`. Uses `run_in_executor` to bridge the blocking channel recv into an asyncio-compatible awaitable without requiring `pyo3-async`.
(&self, py: Python<'py>)
| 998 | /// Uses `run_in_executor` to bridge the blocking channel recv into an |
| 999 | /// asyncio-compatible awaitable without requiring `pyo3-async`. |
| 1000 | fn __anext__<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyAny>> { |
| 1001 | if self.done.load(Ordering::Relaxed) { |
| 1002 | return Err(PyStopAsyncIteration::new_err("stream exhausted")); |
| 1003 | } |
| 1004 | |
| 1005 | let callable = Bound::new( |
| 1006 | py, |
| 1007 | BlockingRecv { |
| 1008 | rx: self.rx.clone(), |
| 1009 | done: self.done.clone(), |
| 1010 | }, |
| 1011 | )?; |
| 1012 | |
| 1013 | let asyncio = py.import("asyncio")?; |
| 1014 | let loop_ = asyncio.call_method0("get_running_loop")?; |
| 1015 | let future = loop_.call_method1("run_in_executor", (py.None(), callable))?; |
| 1016 | Ok(future) |
| 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | // ============================================================================ |