You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code does not work because in the ResponseDatawrite method, if the Reader returns any error, including interrupted kind errors it just passes it up. What it should do, is copy the impl of read_to_end in Read where it just continues. Perhaps spin-locking like this isn't the best solution long term, but it's easy enough, and it's not like anybody is going to stop me.
pubfnattach(server:&mutServer<App>){
server.route(afire::Method::GET,"/test", |_| {Response::new().stream(TestStream::new())});}structTestStream{count:usize,last:Instant,}implTestStream{fnnew() -> Self{Self{count:0,last:Instant::now(),}}}implReadforTestStream{fnread(&mutself,buf:&mut[u8]) -> std::io::Result<usize>{ifself.count > 10{returnOk(0);}let elapsed = self.last.elapsed().as_secs_f64();if elapsed < 0.5{returnErr(std::io::Error::new(
std::io::ErrorKind::Interrupted,"Not enough time has elapsed.",));}self.count += 1;let data = format!("{{\"count\": {}}}", self.count);let bytes = data.as_bytes();let len = bytes.len().min(buf.len());
buf[..len].copy_from_slice(&bytes[..len]);Ok(len)}}
The text was updated successfully, but these errors were encountered:
The following code does not work because in the
ResponseData
write
method, if the Reader returns any error, including interrupted kind errors it just passes it up. What it should do, is copy the impl ofread_to_end
inRead
where it just continues. Perhaps spin-locking like this isn't the best solution long term, but it's easy enough, and it's not like anybody is going to stop me.The text was updated successfully, but these errors were encountered: