(&mut self, py: Python<'_>)
| 955 | } |
| 956 | |
| 957 | fn __next__(&mut self, py: Python<'_>) -> PyResult<Option<PyAgentEvent>> { |
| 958 | if self.done.load(Ordering::Relaxed) { |
| 959 | return Err(PyStopIteration::new_err("stream exhausted")); |
| 960 | } |
| 961 | |
| 962 | let rx = self.rx.clone(); |
| 963 | let done_flag = self.done.clone(); |
| 964 | let result = py.allow_threads(|| { |
| 965 | get_runtime().block_on(async { |
| 966 | let mut guard = rx.lock().await; |
| 967 | guard.recv().await |
| 968 | }) |
| 969 | }); |
| 970 | |
| 971 | match result { |
| 972 | Some(event) => { |
| 973 | let is_end = matches!(event, RustAgentEvent::End { .. }); |
| 974 | let is_error = matches!(event, RustAgentEvent::Error { .. }); |
| 975 | let py_event = PyAgentEvent::from(event); |
| 976 | if is_end || is_error { |
| 977 | done_flag.store(true, Ordering::Relaxed); |
| 978 | } |
| 979 | Ok(Some(py_event)) |
| 980 | } |
| 981 | None => { |
| 982 | done_flag.store(true, Ordering::Relaxed); |
| 983 | Err(PyStopIteration::new_err("stream exhausted")) |
| 984 | } |
| 985 | } |
| 986 | } |
| 987 | |
| 988 | // ------------------------------------------------------------------ |
| 989 | // Async iterator protocol |
nothing calls this directly
no test coverage detected