|
78 | 78 | #![cfg_attr(quicrpc_docsrs, feature(doc_cfg))] |
79 | 79 | use std::{fmt::Debug, future::Future, io, marker::PhantomData, ops::Deref, result}; |
80 | 80 |
|
81 | | -use channel::{mpsc, oneshot}; |
| 81 | +use channel::{mpsc, none::NoSender, oneshot}; |
82 | 82 | /// Processes an RPC request enum and generates trait implementations for use with `irpc`. |
83 | 83 | /// |
84 | 84 | /// This attribute macro may be applied to an enum where each variant represents |
@@ -829,6 +829,25 @@ where |
829 | 829 | } |
830 | 830 | } |
831 | 831 |
|
| 832 | +/// Tuple conversion from inner message to a WithChannels struct without channels |
| 833 | +impl<I, S> From<(I,)> for WithChannels<I, S> |
| 834 | +where |
| 835 | + I: Channels<S, Rx = NoReceiver, Tx = NoSender>, |
| 836 | + S: Service, |
| 837 | +{ |
| 838 | + fn from(inner: (I,)) -> Self { |
| 839 | + let (inner,) = inner; |
| 840 | + Self { |
| 841 | + inner, |
| 842 | + tx: NoSender, |
| 843 | + rx: NoReceiver, |
| 844 | + #[cfg(feature = "spans")] |
| 845 | + #[cfg_attr(quicrpc_docsrs, doc(cfg(feature = "spans")))] |
| 846 | + span: tracing::Span::current(), |
| 847 | + } |
| 848 | + } |
| 849 | +} |
| 850 | + |
832 | 851 | /// Deref so you can access the inner fields directly. |
833 | 852 | /// |
834 | 853 | /// If the inner message has fields named `tx`, `rx` or `span`, you need to use the |
@@ -1082,6 +1101,32 @@ impl<S: Service> Client<S> { |
1082 | 1101 | Ok((update_tx, res_rx)) |
1083 | 1102 | } |
1084 | 1103 | } |
| 1104 | + |
| 1105 | + /// Performs a request for which the server returns nothing. |
| 1106 | + /// |
| 1107 | + /// The returned future completes once the message is sent. |
| 1108 | + pub fn notify<Req>(&self, msg: Req) -> impl Future<Output = Result<()>> + Send + 'static |
| 1109 | + where |
| 1110 | + S: From<Req>, |
| 1111 | + S::Message: From<WithChannels<Req, S>>, |
| 1112 | + Req: Channels<S, Tx = NoSender, Rx = NoReceiver>, |
| 1113 | + { |
| 1114 | + let request = self.request(); |
| 1115 | + async move { |
| 1116 | + match request.await? { |
| 1117 | + Request::Local(request) => { |
| 1118 | + request.send((msg,)).await?; |
| 1119 | + } |
| 1120 | + #[cfg(not(feature = "rpc"))] |
| 1121 | + Request::Remote(_request) => unreachable!(), |
| 1122 | + #[cfg(feature = "rpc")] |
| 1123 | + Request::Remote(request) => { |
| 1124 | + let (_tx, _rx) = request.write(msg).await?; |
| 1125 | + } |
| 1126 | + }; |
| 1127 | + Ok(()) |
| 1128 | + } |
| 1129 | + } |
1085 | 1130 | } |
1086 | 1131 |
|
1087 | 1132 | #[derive(Debug)] |
|
0 commit comments