mirror of
https://github.com/lune-org/lune.git
synced 2024-12-13 13:30:38 +00:00
Fix task.wait breaking after coroutine.resume
This commit is contained in:
parent
c45c78bdc2
commit
dbe6c18d3a
2 changed files with 29 additions and 9 deletions
|
@ -131,16 +131,22 @@ fn coroutine_resume<'lua>(
|
|||
lua: &'lua Lua,
|
||||
value: LuaThreadOrTaskReference,
|
||||
) -> LuaResult<LuaMultiValue<'lua>> {
|
||||
// FIXME: Resume should return true, return vals OR false, error message
|
||||
let sched = lua.app_data_ref::<&TaskScheduler>().unwrap();
|
||||
match value {
|
||||
LuaThreadOrTaskReference::Thread(t) => {
|
||||
let sched = lua.app_data_ref::<&TaskScheduler>().unwrap();
|
||||
let task = sched.create_task(TaskKind::Instant, t, None, true)?;
|
||||
sched.resume_task(task, None)
|
||||
if sched.current_task().is_none() {
|
||||
return Err(LuaError::RuntimeError(
|
||||
"No current task to inherit".to_string(),
|
||||
));
|
||||
}
|
||||
LuaThreadOrTaskReference::TaskReference(t) => lua
|
||||
.app_data_ref::<&TaskScheduler>()
|
||||
.unwrap()
|
||||
.resume_task(t, None),
|
||||
let task = sched.create_task(TaskKind::Instant, t, None, true)?;
|
||||
let current = sched.current_task().unwrap();
|
||||
let result = sched.resume_task(task, None);
|
||||
sched.force_set_current_task(Some(current));
|
||||
result
|
||||
}
|
||||
LuaThreadOrTaskReference::TaskReference(t) => sched.resume_task(t, None),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,8 +158,18 @@ fn coroutine_wrap<'lua>(lua: &'lua Lua, func: LuaFunction) -> LuaResult<LuaFunct
|
|||
false,
|
||||
)?;
|
||||
lua.create_function(move |lua, args: LuaMultiValue| {
|
||||
lua.app_data_ref::<&TaskScheduler>()
|
||||
let sched = lua.app_data_ref::<&TaskScheduler>().unwrap();
|
||||
if sched.current_task().is_none() {
|
||||
return Err(LuaError::RuntimeError(
|
||||
"No current task to inherit".to_string(),
|
||||
));
|
||||
}
|
||||
let current = sched.current_task().unwrap();
|
||||
let result = lua
|
||||
.app_data_ref::<&TaskScheduler>()
|
||||
.unwrap()
|
||||
.resume_task(task, Some(Ok(args)))
|
||||
.resume_task(task, Some(Ok(args)));
|
||||
sched.force_set_current_task(Some(current));
|
||||
result
|
||||
})
|
||||
}
|
||||
|
|
|
@ -98,6 +98,10 @@ impl<'fut> TaskScheduler<'fut> {
|
|||
self.exit_code.set(Some(code));
|
||||
}
|
||||
|
||||
pub(crate) fn force_set_current_task(&self, reference: Option<TaskReference>) {
|
||||
self.tasks_current.set(reference);
|
||||
}
|
||||
|
||||
/**
|
||||
Checks if a task still exists in the scheduler.
|
||||
|
||||
|
@ -147,7 +151,7 @@ impl<'fut> TaskScheduler<'fut> {
|
|||
// Create the task ref to use
|
||||
let guid = if inherit_current_guid {
|
||||
self.current_task()
|
||||
.expect("No current guid to inherit")
|
||||
.ok_or_else(|| LuaError::RuntimeError("No current guid to inherit".to_string()))?
|
||||
.id()
|
||||
} else {
|
||||
let guid = self.guid.get();
|
||||
|
|
Loading…
Reference in a new issue