Skip to content

Commit e389a57

Browse files
committed
Close method for connections
1 parent 967f7bf commit e389a57

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

edge-http/src/io/client.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,13 @@ where
239239

240240
match result {
241241
Ok(true) | Err(_) => {
242-
let mut io = state.io.take().unwrap();
242+
let io = state.io.take();
243243
*self = Self::Unbound(state);
244244

245-
io.close(Close::Both).await.map_err(Error::Io)?;
246-
let _ = io.abort().await;
245+
if let Some(mut io) = io {
246+
io.close(Close::Both).await.map_err(Error::Io)?;
247+
let _ = io.abort().await;
248+
}
247249
}
248250
_ => {
249251
*self = Self::Unbound(state);
@@ -255,6 +257,17 @@ where
255257
Ok(())
256258
}
257259

260+
pub async fn close(mut self) -> Result<(), Error<T::Error>> {
261+
let res = self.complete().await;
262+
263+
if let Some(mut io) = self.unbind().io.take() {
264+
io.close(Close::Both).await.map_err(Error::Io)?;
265+
let _ = io.abort().await;
266+
}
267+
268+
res
269+
}
270+
258271
async fn complete_request(&mut self) -> Result<(), Error<T::Error>> {
259272
self.request_mut()?.io.finish().await?;
260273

0 commit comments

Comments
 (0)