Skip to content

Commit

Permalink
return a result from sse sender
Browse files Browse the repository at this point in the history
in order to allow endpoints to break out of loops
  • Loading branch information
jbr committed Jun 15, 2020
1 parent 48a66f5 commit 276c5ef
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ __internal__bench = []

[dependencies]
async-h1 = { version = "2.0.1", optional = true }
async-sse = "3.0.0"
async-sse = { git = "https://github.com/jbr/async-sse", branch = "handle-dropped-encoder" }
async-std = { version = "1.6.0", features = ["unstable"] }
femme = "2.0.1"
http-types = "2.0.1"
Expand Down
4 changes: 2 additions & 2 deletions examples/sse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use tide::sse;
async fn main() -> Result<(), std::io::Error> {
let mut app = tide::new();
app.at("/sse").get(sse::endpoint(|_req, sender| async move {
sender.send("fruit", "banana", None).await;
sender.send("fruit", "apple", None).await;
sender.send("fruit", "banana", None).await?;
sender.send("fruit", "apple", None).await?;
Ok(())
}));
app.listen("localhost:8080").await?;
Expand Down
4 changes: 2 additions & 2 deletions src/sse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
//!
//! let mut app = tide::new();
//! app.at("/sse").get(sse::endpoint(|_req, sender| async move {
//! sender.send("fruit", "banana", None).await;
//! sender.send("fruit", "apple", None).await;
//! sender.send("fruit", "banana", None).await?;
//! sender.send("fruit", "apple", None).await?;
//! Ok(())
//! }));
//! app.listen("localhost:8080").await?;
Expand Down
11 changes: 8 additions & 3 deletions src/sse/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ impl Sender {

/// Send data from the SSE channel.
///
/// Each message constists of a "name" and "data".
pub async fn send(&self, name: &str, data: impl AsRef<str>, id: Option<&str>) {
self.sender.send(name, data.as_ref(), id).await;
/// Each message consists of a "name" and "data".
pub async fn send(
&self,
name: &str,
data: impl AsRef<str>,
id: Option<&str>,
) -> Result<(), async_sse::DisconnectedError> {
self.sender.send(name, data.as_ref(), id).await
}
}

0 comments on commit 276c5ef

Please sign in to comment.