@@ -9,23 +9,30 @@ pub use tx::ChannelTx;
99use crate :: { Channel , ChannelId , ChannelMsg , ChannelReadHalf } ;
1010
1111#[ derive( Debug ) ]
12- pub struct ChannelCloseOnDrop < S : From < ( ChannelId , ChannelMsg ) > > ( pub Channel < S > ) ;
13- impl < S : From < ( ChannelId , ChannelMsg ) > > Borrow < ChannelReadHalf > for ChannelCloseOnDrop < S > {
12+ pub struct ChannelCloseOnDrop < S : From < ( ChannelId , ChannelMsg ) > + Send + ' static > ( pub Channel < S > ) ;
13+
14+ impl < S : From < ( ChannelId , ChannelMsg ) > + Send + ' static > Borrow < ChannelReadHalf >
15+ for ChannelCloseOnDrop < S >
16+ {
1417 fn borrow ( & self ) -> & ChannelReadHalf {
1518 & self . 0 . read_half
1619 }
1720}
18- impl < S : From < ( ChannelId , ChannelMsg ) > > BorrowMut < ChannelReadHalf > for ChannelCloseOnDrop < S > {
21+
22+ impl < S : From < ( ChannelId , ChannelMsg ) > + Send + ' static > BorrowMut < ChannelReadHalf >
23+ for ChannelCloseOnDrop < S >
24+ {
1925 fn borrow_mut ( & mut self ) -> & mut ChannelReadHalf {
2026 & mut self . 0 . read_half
2127 }
2228}
23- impl < S : From < ( ChannelId , ChannelMsg ) > > Drop for ChannelCloseOnDrop < S > {
29+
30+ impl < S : From < ( ChannelId , ChannelMsg ) > + Send + ' static > Drop for ChannelCloseOnDrop < S > {
2431 fn drop ( & mut self ) {
25- let Self ( channel ) = self ;
26- let _ = channel
27- . write_half
28- . sender
29- . try_send ( ( channel . write_half . id , ChannelMsg :: Close ) . into ( ) ) ;
32+ let id = self . 0 . write_half . id ;
33+ let sender = self . 0 . write_half . sender . clone ( ) ;
34+ tokio :: spawn ( async move {
35+ let _ = sender. send ( ( id , ChannelMsg :: Close ) . into ( ) ) . await ;
36+ } ) ;
3037 }
3138}
0 commit comments