mirror of
https://github.com/CompeyDev/lune-packaging.git
synced 2025-01-09 12:19:09 +00:00
Fix process exit behavior
This commit is contained in:
parent
b414174ee6
commit
589c52f769
2 changed files with 20 additions and 3 deletions
|
@ -4,11 +4,12 @@ use std::{
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
process::{Command, Stdio},
|
process::{Command, Stdio},
|
||||||
sync::Weak,
|
sync::Weak,
|
||||||
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
use mlua::prelude::*;
|
use mlua::prelude::*;
|
||||||
use os_str_bytes::RawOsString;
|
use os_str_bytes::RawOsString;
|
||||||
use smol::channel::Sender;
|
use smol::{channel::Sender, Timer};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
utils::{process::pipe_and_inherit_child_process_stdio, table::TableBuilder},
|
utils::{process::pipe_and_inherit_child_process_stdio, table::TableBuilder},
|
||||||
|
@ -120,10 +121,15 @@ async fn process_exit(lua: &Lua, exit_code: Option<u8>) -> LuaResult<()> {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.upgrade()
|
.upgrade()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
// Send an exit signal to the main thread, which
|
||||||
|
// will try to exit safely and as soon as possible
|
||||||
sender
|
sender
|
||||||
.send(LuneMessage::Exit(exit_code.unwrap_or(0)))
|
.send(LuneMessage::Exit(exit_code.unwrap_or(0)))
|
||||||
.await
|
.await
|
||||||
.map_err(LuaError::external)?;
|
.map_err(LuaError::external)?;
|
||||||
|
// Make sure to block the rest of this thread indefinitely since
|
||||||
|
// the main thread may not register the exit signal right away
|
||||||
|
Timer::after(Duration::MAX).await;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,14 @@
|
||||||
process.exit(0)
|
local function assert(condition, err)
|
||||||
|
if not condition then
|
||||||
|
console.error(err)
|
||||||
|
process.exit(0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
error("Process should have exited successfully")
|
local path = process.cwd .. "asdfghjkl"
|
||||||
|
|
||||||
|
assert(fs.isDir(path), "Process should exit")
|
||||||
|
assert(fs.isDir(path), "Process should exit")
|
||||||
|
assert(fs.isDir(path), "Process should exit")
|
||||||
|
|
||||||
|
error("Process should have exited...")
|
||||||
|
|
Loading…
Reference in a new issue