Skip to content

Commit 2ed3b02

Browse files
committed
Add async feature to conditionally use LocalSet
1 parent b80a1c8 commit 2ed3b02

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ lua52 = ["mlua/lua52"]
1313
lua53 = ["mlua/lua53"]
1414
lua54 = ["mlua/lua54"]
1515
luau = ["mlua/luau"]
16+
async = ["mlua/async", "dep:tokio", "dep:tokio-util"]
1617
send = ["mlua/send"]
1718
vendored = ["mlua/vendored"]
1819

1920
json = ["mlua/serde", "dep:ouroboros", "dep:serde", "dep:serde_json"]
2021
regex = ["dep:regex", "dep:ouroboros", "dep:quick_cache"]
2122
yaml = ["mlua/serde", "dep:ouroboros", "dep:serde", "dep:serde_yaml"]
2223
http = ["dep:http"]
23-
task = ["dep:tokio", "dep:tokio-util", "mlua/async"]
24+
task = ["async"]
2425

2526
[dependencies]
2627
mlua = { version = "0.11" }

src/macros.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(unused_macros)]
2+
13
macro_rules! lua_try {
24
($result:expr) => {
35
match $result {

tests/lib.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,15 @@ async fn run_file(modname: &str) -> Result<()> {
3131
let path = format!("tests/lua/{modname}_tests.lua");
3232
lua.load(Path::new(&path)).exec()?;
3333

34-
let local = tokio::task::LocalSet::new();
35-
let (ok, _results) = local
36-
.run_until(testing.call_async_method::<(bool, Table)>("run", ()))
37-
.await?;
34+
#[cfg(feature = "async")]
35+
let (ok, _results) = {
36+
let local = tokio::task::LocalSet::new();
37+
local
38+
.run_until(testing.call_async_method::<(bool, Table)>("run", ()))
39+
.await?
40+
};
41+
#[cfg(not(feature = "async"))]
42+
let (ok, _results) = testing.call_method::<(bool, Table)>("run", ())?;
3843
if ok {
3944
return Ok(());
4045
}

0 commit comments

Comments
 (0)