Don't keep poll function in environment globals when polling async functions.
This is redundant after deprecating scoped async. Closes #281
This commit is contained in:
parent
9596f2e9ee
commit
8ab0ccf11c
|
@ -2845,11 +2845,10 @@ impl Lua {
|
|||
LightUserData(&ASYNC_POLL_PENDING as *const u8 as *mut c_void)
|
||||
})?;
|
||||
|
||||
// We set `poll` variable in the env table to be able to destroy upvalues
|
||||
self.load(
|
||||
r#"
|
||||
poll = get_poll(...)
|
||||
local poll, pending, yield, unpack = poll, pending, yield, unpack
|
||||
local poll = get_poll(...)
|
||||
local pending, yield, unpack = pending, yield, unpack
|
||||
while true do
|
||||
local ready, res, nres = poll()
|
||||
if ready then
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#![cfg(feature = "async")]
|
||||
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
|
||||
use futures_timer::Delay;
|
||||
|
@ -502,3 +502,25 @@ async fn test_owned_async_call() -> Result<()> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_async_terminate() -> Result<()> {
|
||||
let lua = Lua::new();
|
||||
|
||||
let mutex = Arc::new(Mutex::new(0u32));
|
||||
let mutex2 = mutex.clone();
|
||||
let func = lua.create_async_function(move |_, ()| {
|
||||
let mutex = mutex2.clone();
|
||||
async move {
|
||||
let _guard = mutex.lock();
|
||||
Delay::new(Duration::from_millis(100)).await;
|
||||
Ok(())
|
||||
}
|
||||
})?;
|
||||
|
||||
let _ = tokio::time::timeout(Duration::from_millis(30), func.call_async::<_, ()>(())).await;
|
||||
lua.gc_collect()?;
|
||||
assert!(mutex.try_lock().is_ok());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue