Skip to content

Commit afd7449

Browse files
committed
Add new syntax candy fn to send a stream of updates to the server without any return message.
Basically a streaming version of notify.
1 parent 0db3188 commit afd7449

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/lib.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,37 @@ impl<S: Service> Client<S> {
11971197
}
11981198
}
11991199

1200+
pub fn notify_streaming<Req, Update>(
1201+
&self,
1202+
msg: Req,
1203+
local_update_cap: usize,
1204+
) -> impl Future<Output = Result<mpsc::Sender<Update>>>
1205+
where
1206+
S: From<Req>,
1207+
S::Message: From<WithChannels<Req, S>>,
1208+
Req: Channels<S, Tx = NoSender, Rx = mpsc::Receiver<Update>>,
1209+
Update: RpcMessage,
1210+
{
1211+
let client = self.clone();
1212+
async move {
1213+
let request = client.request().await?;
1214+
match request {
1215+
Request::Local(request) => {
1216+
let (req_tx, req_rx) = mpsc::channel(local_update_cap);
1217+
request.send((msg, NoSender, req_rx)).await?;
1218+
Ok(req_tx)
1219+
}
1220+
#[cfg(not(feature = "rpc"))]
1221+
Request::Remote(_request) => unreachable!(),
1222+
#[cfg(feature = "rpc")]
1223+
Request::Remote(remote) => {
1224+
let (s, _) = remote.write(msg).await?;
1225+
Ok(s.into())
1226+
}
1227+
}
1228+
}
1229+
}
1230+
12001231
/// Performs a request for which the client can send updates, and the server returns a mpsc receiver.
12011232
pub fn bidi_streaming<Req, Update, Res>(
12021233
&self,

0 commit comments

Comments
 (0)