| 26 | |
| 27 | impl ClientConnection { |
| 28 | pub fn blocking_close_output( |
| 29 | &self, |
| 30 | output: &OutputStream, |
| 31 | ) -> Result<(), crate::wasi::io::error::Error> { |
| 32 | let timeout = monotonic_clock::subscribe_duration(TIMEOUT_NS); |
| 33 | let pollable = output.subscribe(); |
| 34 | |
| 35 | self.close_output(); |
| 36 | |
| 37 | loop { |
| 38 | match output.check_write() { |
| 39 | Ok(0) => pollable.block_until(&timeout).expect("timed out"), |
| 40 | Ok(_) => unreachable!( |
| 41 | "After calling close_output, the output stream should never accept new writes again." |
| 42 | ), |
| 43 | Err(StreamError::Closed) => return Ok(()), |
| 44 | Err(StreamError::LastOperationFailed(e)) => return Err(e), |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | } |