1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-22 22:42:48 +03:00

lua: add wezterm.sleep_ms

This will delay for the specified number of milliseconds.
This is an async function; it won't block the gui thread,
it will deschedule running the script and resume it once
the timeout has expired.

refs: #222
This commit is contained in:
Wez Furlong 2020-10-09 21:11:30 -07:00
parent 22b6123624
commit 5a8fc09336

View File

@ -107,6 +107,7 @@ pub fn make_lua_context(config_dir: &Path) -> anyhow::Result<Lua> {
)?;
wezterm_mod.set("on", lua.create_function(register_event)?)?;
wezterm_mod.set("emit", lua.create_async_function(emit_event)?)?;
wezterm_mod.set("sleep_ms", lua.create_async_function(sleep_ms)?)?;
package.set("path", path_array.join(";"))?;
@ -117,6 +118,12 @@ pub fn make_lua_context(config_dir: &Path) -> anyhow::Result<Lua> {
Ok(lua)
}
async fn sleep_ms<'lua>(_: &'lua Lua, milliseconds: u64) -> mlua::Result<()> {
let duration = std::time::Duration::from_millis(milliseconds);
smol::Timer::after(duration).await;
Ok(())
}
/// Returns the system hostname.
/// Errors may occur while retrieving the hostname from the system,
/// or if the hostname isn't a UTF-8 string.