nstreams_core/
subscription.rs1use crate::event::DeliveredEvent;
2
3pub struct Subscription {
5 request_id: String,
6 rx: tokio::sync::mpsc::Receiver<crate::Result<DeliveredEvent>>,
7}
8
9impl Subscription {
10 pub(crate) fn new(
11 request_id: String,
12 rx: tokio::sync::mpsc::Receiver<crate::Result<DeliveredEvent>>,
13 ) -> Self {
14 Self { request_id, rx }
15 }
16
17 pub fn request_id(&self) -> &str {
18 &self.request_id
19 }
20
21 pub async fn next(&mut self) -> Option<crate::Result<DeliveredEvent>> {
22 self.rx.recv().await
23 }
24
25 pub fn into_parts(
26 self,
27 ) -> (
28 String,
29 tokio::sync::mpsc::Receiver<crate::Result<DeliveredEvent>>,
30 ) {
31 (self.request_id, self.rx)
32 }
33}