Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to latest Tokio and Hyper #5

Merged
merged 14 commits into from
May 16, 2021
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:
name: Check consistent formatting
command: cargo fmt && git diff --exit-code
- run: cargo build
- run: cargo test
- run: cargo test --all-features
- run: cargo doc --no-deps
- run: cargo clippy -- -D warnings
- run: cargo clippy --all-features -- -D warnings

- store_artifacts:
path: target/doc
Expand Down
18 changes: 14 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,23 @@ exclude = [
]

[dependencies]
futures = "0.1.25"
futures = "0.3.12"
hyper = { version = "0.14.4", features = ["client", "http1", "tcp"] }
hyper-rustls = { version = "0.22.1", optional = true }
log = "0.4.6"
reqwest = "0.9.11"
tokio-timer = "0.2.11"
pin-project = "1.0.5"
tokio = { version = "1.2.0", features = ["time"] }

[dev-dependencies]
env_logger = "0.7.1"
maplit = "1.0.1"
simplelog = "0.5.3"
tokio = "0.1.16"
tokio = { version = "1.2.0", features = ["macros", "rt-multi-thread"] }

[features]
default = ["rustls"]
rustls = ["hyper-rustls", "hyper/http2"]

[[example]]
name = "tail"
required-features = ["rustls"]
23 changes: 15 additions & 8 deletions examples/tail.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::{env, process, time::Duration};
use std::{env, process, str::from_utf8, time::Duration};

use futures::{future::Future, lazy, stream::Stream};
use futures::{Stream, TryStreamExt};

use eventsource_client as es;

fn main() -> Result<(), es::Error> {
#[tokio::main]
async fn main() -> Result<(), es::Error> {
env_logger::init();

let args: Vec<String> = env::args().collect();
Expand All @@ -28,16 +29,22 @@ fn main() -> Result<(), es::Error> {
.build(),
)
.build();
tokio::run(lazy(|| tail_events(client)));

let mut stream = Box::pin(tail_events(client));
while let Ok(Some(_)) = stream.try_next().await {}

Ok(())
}

fn tail_events(mut client: es::Client) -> impl Future<Item = (), Error = ()> {
fn tail_events(client: es::Client<es::HttpsConnector>) -> impl Stream<Item = Result<(), ()>> {
client
.stream()
.for_each(|event| {
println!("got an event: {}", event.event_type);
Ok(())
.map_ok(|event| {
println!(
"got an event: {}\n{}",
event.event_type,
from_utf8(event.field("data").unwrap_or_default()).unwrap_or_default()
)
})
.map_err(|err| eprintln!("error streaming events: {:?}", err))
}
Loading