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:
parent
22b6123624
commit
5a8fc09336
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user