@ -29,10 +29,8 @@ use std::io::{Read, Write};
use compat ::{ cvt , AllowStd , ContextWaker } ;
use futures ::io ::{ AsyncRead , AsyncWrite } ;
use futures ::{ Sink , Stream } ;
use futures ::{ Sink , SinkExt , S tream } ;
use log ::* ;
use pin_project ::pin_project ;
use std ::future ::Future ;
use std ::pin ::Pin ;
use std ::task ::{ Context , Poll } ;
@ -248,11 +246,8 @@ impl<S> WebSocketStream<S> {
where
S : AsyncRead + AsyncWrite + Unpin ,
{
let f = CloseFuture {
stream : self ,
message : Some ( msg ) ,
} ;
f . await
let msg = msg . map ( | msg | msg . into_owned ( ) ) ;
self . send ( Message ::Close ( msg ) ) . await
}
}
@ -324,29 +319,6 @@ where
}
}
#[ pin_project ]
struct CloseFuture < ' a , T > {
stream : & ' a mut WebSocketStream < T > ,
message : Option < Option < CloseFrame < ' a > > > ,
}
impl < ' a , T > Future for CloseFuture < ' a , T >
where
T : AsyncRead + AsyncWrite + Unpin ,
AllowStd < T > : Read + Write ,
{
type Output = Result < ( ) , WsError > ;
fn poll ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self ::Output > {
let this = self . project ( ) ;
let message = this . message . take ( ) . expect ( "Cannot poll twice" ) ;
Poll ::Ready (
this . stream
. with_context ( Some ( ( ContextWaker ::Write , cx ) ) , | s | s . close ( message ) ) ,
)
}
}
#[ cfg(test) ]
mod tests {
use crate ::compat ::AllowStd ;