@@ -108,16 +108,24 @@ pub enum TxStatus {
108108/// The transmit end of an M-typed channel.
109109#[ async_trait]
110110pub trait Tx < M : RemoteMessage > : std:: fmt:: Debug {
111+ /// Post a message; returning failed deliveries on the return channel, if provided.
112+ /// If provided, the sender is dropped when the message has been
113+ /// enqueued at the channel endpoint.
114+ ///
115+ /// Users should use the `try_post`, and `post` variants directly.
116+ fn do_post ( & self , message : M , return_channel : Option < oneshot:: Sender < SendError < M > > > ) ;
117+
111118 /// Enqueue a `message` on the local end of the channel. The
112119 /// message is either delivered, or we eventually discover that
113120 /// the channel has failed and it will be sent back on `return_channel`.
114121 #[ allow( clippy:: result_large_err) ] // TODO: Consider reducing the size of `SendError`.
115- // TODO: Consider making return channel optional to indicate that the log can be dropped.
116- fn try_post ( & self , message : M , return_channel : oneshot:: Sender < SendError < M > > ) ;
122+ fn try_post ( & self , message : M , return_channel : oneshot:: Sender < SendError < M > > ) {
123+ self . do_post ( message, Some ( return_channel) ) ;
124+ }
117125
118126 /// Enqueue a message to be sent on the channel.
119127 fn post ( & self , message : M ) {
120- self . try_post ( message, oneshot :: channel ( ) . 0 ) ;
128+ self . do_post ( message, None ) ;
121129 }
122130
123131 /// Send a message synchronously, returning when the messsage has
@@ -176,10 +184,12 @@ impl<M: RemoteMessage> MpscTx<M> {
176184
177185#[ async_trait]
178186impl < M : RemoteMessage > Tx < M > for MpscTx < M > {
179- fn try_post ( & self , message : M , return_channel : oneshot:: Sender < SendError < M > > ) {
187+ fn do_post ( & self , message : M , return_channel : Option < oneshot:: Sender < SendError < M > > > ) {
180188 if let Err ( mpsc:: error:: SendError ( message) ) = self . tx . send ( message) {
181- if let Err ( m) = return_channel. send ( SendError ( ChannelError :: Closed , message) ) {
182- tracing:: warn!( "failed to deliver SendError: {}" , m) ;
189+ if let Some ( return_channel) = return_channel {
190+ return_channel
191+ . send ( SendError ( ChannelError :: Closed , message) )
192+ . unwrap_or_else ( |m| tracing:: warn!( "failed to deliver SendError: {}" , m) ) ;
183193 }
184194 }
185195 }
@@ -744,13 +754,13 @@ enum ChannelTxKind<M: RemoteMessage> {
744754
745755#[ async_trait]
746756impl < M : RemoteMessage > Tx < M > for ChannelTx < M > {
747- fn try_post ( & self , message : M , return_channel : oneshot:: Sender < SendError < M > > ) {
757+ fn do_post ( & self , message : M , return_channel : Option < oneshot:: Sender < SendError < M > > > ) {
748758 match & self . inner {
749- ChannelTxKind :: Local ( tx) => tx. try_post ( message, return_channel) ,
750- ChannelTxKind :: Tcp ( tx) => tx. try_post ( message, return_channel) ,
751- ChannelTxKind :: MetaTls ( tx) => tx. try_post ( message, return_channel) ,
752- ChannelTxKind :: Sim ( tx) => tx. try_post ( message, return_channel) ,
753- ChannelTxKind :: Unix ( tx) => tx. try_post ( message, return_channel) ,
759+ ChannelTxKind :: Local ( tx) => tx. do_post ( message, return_channel) ,
760+ ChannelTxKind :: Tcp ( tx) => tx. do_post ( message, return_channel) ,
761+ ChannelTxKind :: MetaTls ( tx) => tx. do_post ( message, return_channel) ,
762+ ChannelTxKind :: Sim ( tx) => tx. do_post ( message, return_channel) ,
763+ ChannelTxKind :: Unix ( tx) => tx. do_post ( message, return_channel) ,
754764 }
755765 }
756766
0 commit comments