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

Method next

sdk/node/src/lib.rs:1148–1190  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

1146 /// When `done` is true, the stream is exhausted.
1147 #[napi]
1148 pub async fn next(&self) -> napi::Result<NextResult> {
1149 if self.done.load(Ordering::Relaxed) {
1150 return Ok(NextResult {
1151 value: None,
1152 done: true,
1153 });
1154 }
1155 let rx = self.rx.clone();
1156 let done_flag = self.done.clone();
1157 let result = get_runtime()
1158 .spawn(async move {
1159 let mut guard = rx.lock().await;
1160 guard.recv().await
1161 })
1162 .await
1163 .map_err(|e| napi::Error::from_reason(format!("Task join error: {e}")))?;
1164 match result {
1165 Some(event) => {
1166 let is_end = matches!(event, RustAgentEvent::End { .. });
1167 let is_error = matches!(event, RustAgentEvent::Error { .. });
1168 let js_event = AgentEvent::from(event);
1169 if is_end || is_error {
1170 done_flag.store(true, Ordering::Relaxed);
1171 Ok(NextResult {
1172 value: Some(js_event),
1173 done: true,
1174 })
1175 } else {
1176 Ok(NextResult {
1177 value: Some(js_event),
1178 done: false,
1179 })
1180 }
1181 }
1182 None => {
1183 done_flag.store(true, Ordering::Relaxed);
1184 Ok(NextResult {
1185 value: None,
1186 done: true,
1187 })
1188 }
1189 }
1190 }
1191}
1192
1193// ============================================================================

Callers 15

collectStreamTextFunction · 0.45
runFunction · 0.45
onceFunction · 0.45
testStreamingMethod · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45

Calls 5

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

Tested by

no test coverage detected