From 3b5a37628fb12e81971c41d6c4703134b5d63be2 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 19 Jun 2021 16:51:40 +0300 Subject: [PATCH] v watch: allow customising the auto-restart timeout for the workers with an env variable VWATCH_TIMEOUT --- cmd/tools/vwatch.v | 14 +++++++++++--- cmd/v/help/watch.txt | 3 +++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/cmd/tools/vwatch.v b/cmd/tools/vwatch.v index eaa3100c66..310eb04b8a 100644 --- a/cmd/tools/vwatch.v +++ b/cmd/tools/vwatch.v @@ -5,7 +5,7 @@ import time import term import flag -const scan_timeout_s = 5 * 60 +const scan_timeout_s = get_scan_timeout_seconds() const max_v_cycles = 1000 @@ -15,8 +15,16 @@ const scan_period_ms = 1000 / scan_frequency_hz const max_scan_cycles = scan_timeout_s * scan_frequency_hz +fn get_scan_timeout_seconds() int { + env_vw_timeout := os.getenv('VWATCH_TIMEOUT').int() + if env_vw_timeout == 0 { + return 5 * 60 + } + return env_vw_timeout +} + // -// Implements `v -watch file.v` , `v -watch run file.v` etc. +// Implements `v watch file.v` , `v watch run file.v` etc. // With this command, V will collect all .v files that are needed for the // compilation, then it will enter an infinite loop, monitoring them for // changes. @@ -25,7 +33,7 @@ const max_scan_cycles = scan_timeout_s * scan_frequency_hz // still running, then rerun/recompile/etc. // // In effect, this makes it easy to have an editor session and a separate -// terminal, running just `v -watch run file.v`, and you will see your +// terminal, running just `v watch run file.v`, and you will see your // changes right after you save your .v file in your editor. // // diff --git a/cmd/v/help/watch.txt b/cmd/v/help/watch.txt index 66c51457b8..9b6920711d 100644 --- a/cmd/v/help/watch.txt +++ b/cmd/v/help/watch.txt @@ -23,3 +23,6 @@ Options: --after A command to execute *after* each re-run. Example: --after 'rm -rf /tmp/v/' +You can also customise the timeout, after `v watch` will re-start a monitored +program automatically, even if it was not changed by setting the enviroment +variable VWATCH_TIMEOUT (in seconds). By default, it is 5 min. (300 seconds).