Skip to content

Commit 8de75d1

Browse files
committed
Update tokio to 1.0 for async examples
1 parent b6ff501 commit 8de75d1

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ rustyline = "7.0"
6161
criterion = "0.3"
6262
trybuild = "1.0"
6363
futures = "0.3.5"
64-
hyper = "0.13"
65-
reqwest = { version = "0.10", features = ["json"] }
66-
tokio = { version = "0.2", features = ["full"] }
64+
hyper = { version = "0.14", features = ["client", "server"] }
65+
reqwest = { version = "0.11", features = ["json"] }
66+
tokio = { version = "1.0", features = ["full"] }
6767
futures-timer = "3.0"
6868
serde_json = "1.0"
6969

examples/async_http_client.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ use std::collections::HashMap;
22
use std::sync::Arc;
33

44
use bstr::BString;
5-
use hyper::{body::Body as HyperBody, Client as HyperClient};
6-
use tokio::{stream::StreamExt, sync::Mutex};
5+
use hyper::body::{Body as HyperBody, HttpBody as _};
6+
use hyper::Client as HyperClient;
7+
use tokio::sync::Mutex;
78

89
use mlua::{Error, Lua, Result, UserData, UserDataMethods};
910

@@ -20,8 +21,8 @@ impl UserData for BodyReader {
2021
fn add_methods<'lua, M: UserDataMethods<'lua, Self>>(methods: &mut M) {
2122
methods.add_async_method("read", |_, reader, ()| async move {
2223
let mut reader = reader.0.lock().await;
23-
let bytes = reader.try_next().await.map_err(Error::external)?;
24-
if let Some(bytes) = bytes {
24+
if let Some(bytes) = reader.data().await {
25+
let bytes = bytes.map_err(Error::external)?;
2526
return Ok(Some(BString::from(bytes.as_ref())));
2627
}
2728
Ok(None)

examples/async_tcp_server.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::net::Shutdown;
21
use std::sync::Arc;
32

43
use bstr::BString;
@@ -55,7 +54,7 @@ impl UserData for LuaTcpStream {
5554
});
5655

5756
methods.add_async_method("close", |_, stream, ()| async move {
58-
stream.0.lock().await.shutdown(Shutdown::Both)?;
57+
stream.0.lock().await.shutdown().await?;
5958
Ok(())
6059
});
6160
}

0 commit comments

Comments
 (0)