diff --git a/docs/changelog.md b/docs/changelog.md index 4e163928d..3ad30826b 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -204,6 +204,9 @@ As features stabilize some brief notes about them will accumulate here. * wezterm now also searches `$XDG_CONFIG_DIRS` as well as `$XDG_CONFIG_HOME` when searching for config files. Thanks to [@jmbaur](https://github.com/jmbaur)! [#3146](https://github.com/wez/wezterm/pull/3146) +* [wezterm.time.call_after](config/lua/wezterm.time/call_after.md) now accepts + fractional numbers of seconds. + [#3287](https://github.com/wez/wezterm/issues/3287) #### Updated * Bundled harfbuzz updated to version 6.0.0 diff --git a/docs/config/lua/wezterm.time/call_after.md b/docs/config/lua/wezterm.time/call_after.md index 62989df92..db7eb376c 100644 --- a/docs/config/lua/wezterm.time/call_after.md +++ b/docs/config/lua/wezterm.time/call_after.md @@ -36,3 +36,6 @@ With great power comes great responsibility: if you schedule a lot of frequent callbacks, or frequently reload your configuration in this way, you may increase the CPU load on your system because you are asking it to work harder. +*Since: nightly builds only* + +You can use fractional seconds to delay by more precise intervals. diff --git a/lua-api-crates/time-funcs/src/lib.rs b/lua-api-crates/time-funcs/src/lib.rs index deda28089..684ccbf6a 100644 --- a/lua-api-crates/time-funcs/src/lib.rs +++ b/lua-api-crates/time-funcs/src/lib.rs @@ -61,7 +61,7 @@ struct ScheduledEvent { /// their callback function user_event_id: String, /// The delay after which to run their callback - interval_seconds: u64, + interval_seconds: f64, } impl ScheduledEvent { @@ -93,7 +93,7 @@ impl ScheduledEvent { } async fn run(self, lua: &Lua, generation: usize) -> mlua::Result<()> { - let duration = std::time::Duration::from_secs(self.interval_seconds); + let duration = std::time::Duration::from_secs_f64(self.interval_seconds); smol::Timer::after(duration).await; // Skip doing anything of consequence if the generation has // changed. @@ -148,7 +148,7 @@ pub fn register(lua: &Lua) -> anyhow::Result<()> { time_mod.set( "call_after", - lua.create_function(|lua, (interval_seconds, func): (u64, mlua::Function)| { + lua.create_function(|lua, (interval_seconds, func): (f64, mlua::Function)| { let user_event_id = wrap_callback(lua, func)?; let event = ScheduledEvent {