@@ -86,7 +86,7 @@ impl<T, U> Sender<T, U> {
8686        } 
8787        let  ( tx,  rx)  = oneshot:: channel ( ) ; 
8888        self . inner 
89-             . send ( Envelope ( Some ( ( val,  Callback :: Retry ( tx ) ) ) ) ) 
89+             . send ( Envelope ( Some ( ( val,  Callback :: Retry ( Some ( tx ) ) ) ) ) ) 
9090            . map ( move  |_| rx) 
9191            . map_err ( |mut  e| ( e. 0 ) . 0 . take ( ) . expect ( "envelope not dropped" ) . 0 ) 
9292    } 
@@ -97,7 +97,7 @@ impl<T, U> Sender<T, U> {
9797        } 
9898        let  ( tx,  rx)  = oneshot:: channel ( ) ; 
9999        self . inner 
100-             . send ( Envelope ( Some ( ( val,  Callback :: NoRetry ( tx ) ) ) ) ) 
100+             . send ( Envelope ( Some ( ( val,  Callback :: NoRetry ( Some ( tx ) ) ) ) ) ) 
101101            . map ( move  |_| rx) 
102102            . map_err ( |mut  e| ( e. 0 ) . 0 . take ( ) . expect ( "envelope not dropped" ) . 0 ) 
103103    } 
@@ -124,7 +124,7 @@ impl<T, U> UnboundedSender<T, U> {
124124    pub ( crate )  fn  try_send ( & mut  self ,  val :  T )  -> Result < RetryPromise < T ,  U > ,  T >  { 
125125        let  ( tx,  rx)  = oneshot:: channel ( ) ; 
126126        self . inner 
127-             . send ( Envelope ( Some ( ( val,  Callback :: Retry ( tx ) ) ) ) ) 
127+             . send ( Envelope ( Some ( ( val,  Callback :: Retry ( Some ( tx ) ) ) ) ) ) 
128128            . map ( move  |_| rx) 
129129            . map_err ( |mut  e| ( e. 0 ) . 0 . take ( ) . expect ( "envelope not dropped" ) . 0 ) 
130130    } 
@@ -198,33 +198,59 @@ impl<T, U> Drop for Envelope<T, U> {
198198} 
199199
200200pub ( crate )  enum  Callback < T ,  U >  { 
201-     Retry ( oneshot:: Sender < Result < U ,  ( crate :: Error ,  Option < T > ) > > ) , 
202-     NoRetry ( oneshot:: Sender < Result < U ,  crate :: Error > > ) , 
201+     Retry ( Option < oneshot:: Sender < Result < U ,  ( crate :: Error ,  Option < T > ) > > > ) , 
202+     NoRetry ( Option < oneshot:: Sender < Result < U ,  crate :: Error > > > ) , 
203+ } 
204+ 
205+ impl < T ,  U >  Drop  for  Callback < T ,  U >  { 
206+     fn  drop ( & mut  self )  { 
207+         // FIXME(nox): What errors do we want here? 
208+         let  error = crate :: Error :: new_user_dispatch_gone ( ) . with ( if  std:: thread:: panicking ( )  { 
209+             "user code panicked" 
210+         }  else  { 
211+             "runtime dropped the dispatch task" 
212+         } ) ; 
213+ 
214+         match  self  { 
215+             Callback :: Retry ( tx)  => { 
216+                 if  let  Some ( tx)  = tx. take ( )  { 
217+                     let  _ = tx. send ( Err ( ( error,  None ) ) ) ; 
218+                 } 
219+             } 
220+             Callback :: NoRetry ( tx)  => { 
221+                 if  let  Some ( tx)  = tx. take ( )  { 
222+                     let  _ = tx. send ( Err ( error) ) ; 
223+                 } 
224+             } 
225+         } 
226+     } 
203227} 
204228
205229impl < T ,  U >  Callback < T ,  U >  { 
206230    #[ cfg( feature = "http2" ) ]  
207231    pub ( crate )  fn  is_canceled ( & self )  -> bool  { 
208232        match  * self  { 
209-             Callback :: Retry ( ref  tx)  => tx. is_closed ( ) , 
210-             Callback :: NoRetry ( ref  tx)  => tx. is_closed ( ) , 
233+             Callback :: Retry ( Some ( ref  tx) )  => tx. is_closed ( ) , 
234+             Callback :: NoRetry ( Some ( ref  tx) )  => tx. is_closed ( ) , 
235+             _ => unreachable ! ( ) , 
211236        } 
212237    } 
213238
214239    pub ( crate )  fn  poll_canceled ( & mut  self ,  cx :  & mut  task:: Context < ' _ > )  -> Poll < ( ) >  { 
215240        match  * self  { 
216-             Callback :: Retry ( ref  mut  tx)  => tx. poll_closed ( cx) , 
217-             Callback :: NoRetry ( ref  mut  tx)  => tx. poll_closed ( cx) , 
241+             Callback :: Retry ( Some ( ref  mut  tx) )  => tx. poll_closed ( cx) , 
242+             Callback :: NoRetry ( Some ( ref  mut  tx) )  => tx. poll_closed ( cx) , 
243+             _ => unreachable ! ( ) , 
218244        } 
219245    } 
220246
221-     pub ( crate )  fn  send ( self ,  val :  Result < U ,  ( crate :: Error ,  Option < T > ) > )  { 
247+     pub ( crate )  fn  send ( mut   self ,  val :  Result < U ,  ( crate :: Error ,  Option < T > ) > )  { 
222248        match  self  { 
223-             Callback :: Retry ( tx)  => { 
224-                 let  _ = tx. send ( val) ; 
249+             Callback :: Retry ( ref   mut   tx)  => { 
250+                 let  _ = tx. take ( ) . unwrap ( ) . send ( val) ; 
225251            } 
226-             Callback :: NoRetry ( tx)  => { 
227-                 let  _ = tx. send ( val. map_err ( |e| e. 0 ) ) ; 
252+             Callback :: NoRetry ( ref   mut   tx)  => { 
253+                 let  _ = tx. take ( ) . unwrap ( ) . send ( val. map_err ( |e| e. 0 ) ) ; 
228254            } 
229255        } 
230256    } 
0 commit comments