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

time: call_after accepts fractional seconds

I thought I'd hooked it up that way from the start, but apparently not!

refs: https://github.com/wez/wezterm/issues/3287
This commit is contained in:
Wez Furlong 2023-03-19 10:29:19 -07:00
parent 402949d787
commit e70ec47134
No known key found for this signature in database
GPG Key ID: 7A7F66A31EC9B387
3 changed files with 9 additions and 3 deletions

View File

@ -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

View File

@ -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.

View File

@ -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 {