Update tokio to 1.0 for async examples

This commit is contained in:
Alex Orlenko 2021-01-16 14:07:26 +00:00
parent b6ff501b8c
commit 8de75d1c18
3 changed files with 9 additions and 9 deletions

View file

@ -61,9 +61,9 @@ rustyline = "7.0"
criterion = "0.3"
trybuild = "1.0"
futures = "0.3.5"
hyper = "0.13"
reqwest = { version = "0.10", features = ["json"] }
tokio = { version = "0.2", features = ["full"] }
hyper = { version = "0.14", features = ["client", "server"] }
reqwest = { version = "0.11", features = ["json"] }
tokio = { version = "1.0", features = ["full"] }
futures-timer = "3.0"
serde_json = "1.0"

View file

@ -2,8 +2,9 @@ use std::collections::HashMap;
use std::sync::Arc;
use bstr::BString;
use hyper::{body::Body as HyperBody, Client as HyperClient};
use tokio::{stream::StreamExt, sync::Mutex};
use hyper::body::{Body as HyperBody, HttpBody as _};
use hyper::Client as HyperClient;
use tokio::sync::Mutex;
use mlua::{Error, Lua, Result, UserData, UserDataMethods};
@ -20,8 +21,8 @@ impl UserData for BodyReader {
fn add_methods<'lua, M: UserDataMethods<'lua, Self>>(methods: &mut M) {
methods.add_async_method("read", |_, reader, ()| async move {
let mut reader = reader.0.lock().await;
let bytes = reader.try_next().await.map_err(Error::external)?;
if let Some(bytes) = bytes {
if let Some(bytes) = reader.data().await {
let bytes = bytes.map_err(Error::external)?;
return Ok(Some(BString::from(bytes.as_ref())));
}
Ok(None)

View file

@ -1,4 +1,3 @@
use std::net::Shutdown;
use std::sync::Arc;
use bstr::BString;
@ -55,7 +54,7 @@ impl UserData for LuaTcpStream {
});
methods.add_async_method("close", |_, stream, ()| async move {
stream.0.lock().await.shutdown(Shutdown::Both)?;
stream.0.lock().await.shutdown().await?;
Ok(())
});
}