Skip to content

Commit

Permalink
Update examples to latest Tokio/Futures
Browse files Browse the repository at this point in the history
  • Loading branch information
bradfier committed Feb 1, 2024
1 parent fff2d89 commit a52193b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ edition = "2018"
thiserror = "1.0"
tokio = { version = "1", features = ["rt", "rt-multi-thread", "net", "io-util", "time", "macros"] }
tokio-util = { version = "0.7", features = ["codec"] }
futures = "0.3.30"
6 changes: 3 additions & 3 deletions examples/simple.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use rmonitor::codec::RMonitorDecoder;
use std::error::Error;
use std::time::Duration;
use futures::StreamExt;
use tokio::net::TcpStream;
use tokio::stream::StreamExt;
use tokio::time::timeout;
use tokio_util::codec::FramedRead;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let stream = TcpStream::connect("127.0.0.1:4000").await?;
let stream = TcpStream::connect("127.0.0.1:50000").await?;

let mut reader = FramedRead::new(stream, RMonitorDecoder::new_with_max_length(2048));

while let Ok(Some(Ok(event))) = timeout(Duration::from_millis(10), reader.next()).await {
while let Ok(Some(Ok(event))) = timeout(Duration::from_secs(5), reader.next()).await {
println!("{:?}", event);
}

Expand Down
2 changes: 1 addition & 1 deletion examples/sync.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bytes::{BufMut, BytesMut};
use tokio_util::bytes::{BufMut, BytesMut};
use rmonitor::codec::RMonitorDecoder;
use std::io::Read;
use std::net::TcpStream;
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! use rmonitor::RMonitorDecoder;
//! # use std::error::Error;
//! use tokio::net::TcpStream;
//! # use tokio::stream::StreamExt;
//! use futures::stream::StreamExt;
//! use tokio_util::codec::FramedRead;
//!
//! #[tokio::main]
Expand Down

0 comments on commit a52193b

Please sign in to comment.