Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/ocaml-rewatch-watch-settle.polish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- OCaml rewatch: watch mode starts a rebuild as soon as the burst of events from a save has settled, instead of always waiting 50 ms. https://github.com/rescript-lang/rescript/pull/8873
23 changes: 21 additions & 2 deletions rewatch-ocaml/watcher.ml
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,27 @@ let run_locked ~native_create ~report_native_fallback ~root ~prod ~features
| Native_watcher.Failed message ->
Some {message; scope; snapshot = previous}
| Native_watcher.Changed events -> (
delay 0.05;
let events = events @ Native_watcher.drain watcher in
(* Collect the rest of the burst an editor's save produces: wait until
no event has arrived for [quiet] seconds, at most [limit] seconds in
all. Changes arriving later start another build. A clock set back
ends the wait too. *)
let quiet = 0.01
and limit = 0.05 in
let started = Unix.gettimeofday () in
let rec settle collected last_event =
let now = Unix.gettimeofday () in
if
now -. last_event >= quiet
|| now -. started >= limit
|| now < last_event
then collected
else (
delay 0.002;
match Native_watcher.drain watcher with
| [] -> settle collected last_event
| more -> settle (collected @ more) (Unix.gettimeofday ()))
in
let events = settle events started in
let direct =
direct_content_changes watcher scope symlink_targets events
in
Expand Down
Loading