-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
252 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//! Demonstrates usage of the SSE connection manager. | ||
extern crate reqwest_0_12 as reqwest; | ||
Check failure on line 3 in russe/examples/manager.rs
|
||
|
||
use futures_util::StreamExt as _; | ||
use reqwest::{Method, Request}; | ||
use russe::reqwest_0_12::Manager; | ||
Check failure on line 7 in russe/examples/manager.rs
|
||
use tokio_stream::wrappers::UnboundedReceiverStream; | ||
|
||
#[tokio::main(flavor = "current_thread")] | ||
async fn main() -> eyre::Result<()> { | ||
color_eyre::install()?; | ||
|
||
let client = reqwest::Client::default(); | ||
|
||
let mut req = Request::new(Method::GET, "https://sse.dev/test".parse().unwrap()); | ||
let headers = req.headers_mut(); | ||
headers.insert("accept", russe::MEDIA_TYPE_STR.parse().unwrap()); | ||
|
||
let mut manager = Manager::new(&client, req); | ||
|
||
let (_task_handle, events) = manager.send().await.unwrap(); | ||
|
||
let mut event_stream = UnboundedReceiverStream::new(events); | ||
|
||
while let Some(Ok(ev)) = event_stream.next().await { | ||
println!("{ev:?}"); | ||
|
||
if let russe::Event::Message(msg) = ev { | ||
if let Some(id) = msg.id { | ||
manager.commit_id(id); | ||
} | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.