MCPcopy Index your code
hub / github.com/AI45Lab/Code / __next__

Method __next__

sdk/python/src/lib.rs:957–986  ·  view source on GitHub ↗
(&mut self, py: Python<'_>)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

block_onMethod · 0.80
storeMethod · 0.80
get_runtimeFunction · 0.70
loadMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected