#[allow(clippy::should_implement_trait)]
impl {{ handle_name }} {
/// Advance the stream and return the next chunk JSON, or `""` on clean
/// end-of-stream. Returns `Err(message)` on a stream-level error.
pub fn next(&mut self) -> Result<String, String> {
let mut guard = self
.stream
.lock()
.map_err(|_| "{{ handle_name }}::next: stream mutex poisoned".to_string())?;
let stream = match guard.as_mut() {
Some(s) => s,
None => return Ok(String::new()),
};
use ::futures_util::StreamExt;
match crate::__alef_tokio_runtime().block_on(stream.next()) {
Some(Ok(item)) => ::serde_json::to_string(&item).map_err(|e| e.to_string()),
Some(Err(e)) => {
*guard = None;
Err(e.to_string())
}
None => {
*guard = None;
Ok(String::new())
}
}
}
}