File tree 3 files changed +25
-24
lines changed
3 files changed +25
-24
lines changed Original file line number Diff line number Diff line change @@ -4,8 +4,8 @@ use tide::sse;
4
4
async fn main ( ) -> Result < ( ) , std:: io:: Error > {
5
5
let mut app = tide:: new ( ) ;
6
6
app. at ( "/sse" ) . get ( sse:: endpoint ( |_req, sender| async move {
7
- sender. send ( "fruit" , "banana" ) . await ;
8
- sender. send ( "fruit" , "apple" ) . await ;
7
+ sender. send ( "fruit" , "banana" , None ) . await ;
8
+ sender. send ( "fruit" , "apple" , None ) . await ;
9
9
Ok ( ( ) )
10
10
} ) ) ;
11
11
app. listen ( "localhost:8080" ) . await ?;
Original file line number Diff line number Diff line change 18
18
//!
19
19
//! let mut app = tide::new();
20
20
//! app.at("/sse").get(sse::endpoint(|_req, sender| async move {
21
- //! sender.send("fruit", "banana").await;
22
- //! sender.send("fruit", "apple").await;
21
+ //! sender.send("fruit", "banana", None ).await;
22
+ //! sender.send("fruit", "apple", None ).await;
23
23
//! Ok(())
24
24
//! }));
25
25
//! app.listen("localhost:8080").await?;
26
26
//! # Ok(()) }) }
27
27
//! ```
28
28
29
29
mod endpoint;
30
+ mod sender;
30
31
mod upgrade;
31
32
32
33
pub use endpoint:: { endpoint, SseEndpoint } ;
34
+ pub use sender:: Sender ;
33
35
pub use upgrade:: upgrade;
34
-
35
- /// An SSE message sender.
36
- #[ derive( Debug ) ]
37
- pub struct Sender {
38
- sender : async_sse:: Sender ,
39
- }
40
-
41
- impl Sender {
42
- /// Create a new instance of `Sender`.
43
- fn new ( sender : async_sse:: Sender ) -> Self {
44
- Self { sender }
45
- }
46
-
47
- /// Send data from the SSE channel.
48
- ///
49
- /// Each message constists of a "name" and "data".
50
- pub async fn send ( & self , name : & str , data : impl AsRef < [ u8 ] > ) {
51
- self . sender . send ( name, data. as_ref ( ) , None ) . await ;
52
- }
53
- }
Original file line number Diff line number Diff line change
1
+ /// An SSE message sender.
2
+ #[ derive( Debug ) ]
3
+ pub struct Sender {
4
+ sender : async_sse:: Sender ,
5
+ }
6
+
7
+ impl Sender {
8
+ /// Create a new instance of `Sender`.
9
+ pub ( crate ) fn new ( sender : async_sse:: Sender ) -> Self {
10
+ Self { sender }
11
+ }
12
+
13
+ /// Send data from the SSE channel.
14
+ ///
15
+ /// Each message constists of a "name" and "data".
16
+ pub async fn send ( & self , name : & str , data : impl AsRef < str > , id : Option < & str > ) {
17
+ self . sender . send ( name, data. as_ref ( ) . as_bytes ( ) , id) . await ;
18
+ }
19
+ }
You can’t perform that action at this time.
0 commit comments