diff options
author | Alex Orlenko <zxteam@protonmail.com> | 2023-04-26 15:34:15 +0100 |
---|---|---|
committer | Alex Orlenko <zxteam@protonmail.com> | 2023-04-26 15:40:48 +0100 |
commit | 4daa7de9978d7dfe43c40e8081a94aaaacf48645 (patch) | |
tree | 5a37267fec3ba0d650119c54b1e118bf6bfacf80 /tests/async.rs | |
parent | bd68a155c02c1a684cc9c96f43e446581ff10222 (diff) | |
download | mlua-4daa7de9978d7dfe43c40e8081a94aaaacf48645.zip |
Various improvements for owned types, including:
- tests
- shortcuts for `OwnedFunction` and `OwnedAnyUserData`
Diffstat (limited to 'tests/async.rs')
-rw-r--r-- | tests/async.rs | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/tests/async.rs b/tests/async.rs index 9ba06da..bc1448f 100644 --- a/tests/async.rs +++ b/tests/async.rs @@ -271,7 +271,7 @@ async fn test_async_thread() -> Result<()> { } #[test] -fn test_async_thread_leak() -> Result<()> { +fn test_async_thread_capture() -> Result<()> { let lua = Lua::new(); let f = lua.create_async_function(move |_lua, v: Value| async move { @@ -285,10 +285,6 @@ fn test_async_thread_leak() -> Result<()> { thread.resume::<_, ()>("abc").unwrap(); drop(thread); - // Without running garbage collection, the captured `v` would trigger "reference leak detected" error - // with `cfg(mlua_test)` - lua.gc_collect()?; - Ok(()) } @@ -488,3 +484,21 @@ async fn test_async_thread_error() -> Result<()> { Ok(()) } + +#[cfg(all(feature = "unstable", not(feature = "send")))] +#[tokio::test] +async fn test_owned_async_call() -> Result<()> { + let lua = Lua::new(); + + let hello = lua + .create_async_function(|_, name: String| async move { + Delay::new(Duration::from_millis(10)).await; + Ok(format!("hello, {}!", name)) + })? + .into_owned(); + drop(lua); + + assert_eq!(hello.call_async::<_, String>("alex").await?, "hello, alex!"); + + Ok(()) +} |