From 7e7cfd7cd0ab52754831f6d40a9bb4e55d037543 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Sun, 20 Aug 2023 14:11:48 -0500 Subject: [PATCH] Add some different debugging --- src/lune/globals/require/context.rs | 8 ++------ src/lune/scheduler/impl_runner.rs | 4 +++- tests/require/tests/async_sequential.luau | 4 ++++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/lune/globals/require/context.rs b/src/lune/globals/require/context.rs index fcb9532..83cc458 100644 --- a/src/lune/globals/require/context.rs +++ b/src/lune/globals/require/context.rs @@ -136,9 +136,7 @@ impl<'lua> RequireContext<'lua> { .lua .registry_value::>(k) .expect("Missing require result in lua registry"); - let multi = LuaMultiValue::from_vec(multi_vec); - println!("Got multi value from cache: {multi:?}"); - Ok(multi) + Ok(LuaMultiValue::from_vec(multi_vec)) } } } @@ -193,13 +191,13 @@ impl<'lua> RequireContext<'lua> { // Schedule the thread to run, wait for it to finish running let thread_id = sched.push_back(file_thread, ())?; + println!("Waiting for thread with id {thread_id:?}"); let thread_res = sched.wait_for_thread(thread_id).await; // Return the result of the thread, storing any lua value(s) in the registry match thread_res { Err(e) => Err(e), Ok(v) => { - println!("Got multi value from require: {v:?}"); let multi_vec = v.into_vec(); let multi_key = self .lua @@ -260,8 +258,6 @@ impl<'lua> RequireContext<'lua> { .expect("Pending require broadcaster was unexpectedly removed"); broadcast_tx.send(()).ok(); - println!("Got return value from require: {load_val:?}"); - load_val } diff --git a/src/lune/scheduler/impl_runner.rs b/src/lune/scheduler/impl_runner.rs index f6d5511..8e66333 100644 --- a/src/lune/scheduler/impl_runner.rs +++ b/src/lune/scheduler/impl_runner.rs @@ -42,6 +42,7 @@ where // Resume the thread, ensuring that the schedulers // current thread id is set correctly for error catching + println!("Resuming thread with id {thread_id:?}"); self.state.set_current_thread_id(Some(thread_id)); let res = thread.resume::<_, LuaMultiValue>(args); self.state.set_current_thread_id(None); @@ -56,7 +57,8 @@ where self.lua.emit_error(err.clone()); } - // Send results of resuming this thread to any listeners + // If the thread has finished running completely, + // send results of final resume to any listeners if let Some(sender) = self.thread_senders.borrow_mut().remove(&thread_id) { if sender.receiver_count() > 0 { let stored = match res { diff --git a/tests/require/tests/async_sequential.luau b/tests/require/tests/async_sequential.luau index de4fb71..17e0b35 100644 --- a/tests/require/tests/async_sequential.luau +++ b/tests/require/tests/async_sequential.luau @@ -2,10 +2,14 @@ local task = require("@lune/task") print("Requiring 1") local module1 = require("./modules/async") +print("Required 1") print("Requiring 2") local module2 = require("./modules/async") +print("Required 2") +print("Waiting") task.wait(1) +print("Waited") assert(type(module1) == "table", "Required module1 did not return a table") assert(module1.Foo == "Bar", "Required module1 did not contain correct values")