terminal user interface to jujutsu. Focused on speed and clarity
9
fork

Configure Feed

Select the types of activity you want to include in your feed.

extract reusable picos debouncer helper

+47 -16
+9 -16
jj_tui/bin/global_funcs.ml
··· 37 37 result |> Lwd.get 38 38 ;; 39 39 40 - let current_computation = ref (Promise.of_value ()) 41 - let update_debounce_computation = ref (Promise.of_value ()) 42 - let pending_snapshot = ref false 43 - 44 40 (**Updates the status windows; Without snapshotting the working copy by default 45 41 This should be called after any command that performs a change *) 46 42 let update_views ?(cause_snapshot = false) () = ··· 63 59 Vars.ui_state.jj_change_files $= files_list) 64 60 ;; 65 61 62 + let update_views_debouncer = 63 + Jj_tui.Debounce.make 64 + ~delay:0.05 65 + ~merge:( || ) 66 + ~run:(fun cause_snapshot -> update_views ~cause_snapshot ()) 67 + () 68 + ;; 69 + 66 70 let update_views_async ?(cause_snapshot = false) () = 67 - (* Coalesce rapid refresh requests while scrolling/navigation is active. *) 68 - pending_snapshot := !pending_snapshot || cause_snapshot; 69 - Promise.terminate_after ~seconds:0. !update_debounce_computation; 70 - update_debounce_computation 71 - := Flock.fork_as_promise (fun () -> 72 - Control.sleep ~seconds:0.05; 73 - let should_snapshot = !pending_snapshot in 74 - pending_snapshot := false; 75 - Promise.terminate_after ~seconds:0. !current_computation; 76 - current_computation 77 - := Flock.fork_as_promise (fun () -> 78 - update_views ~cause_snapshot:should_snapshot ())) 71 + Jj_tui.Debounce.push update_views_debouncer cause_snapshot 79 72 ;; 80 73 81 74 (**Updates the status windows; Without snapshotting the working copy by default
+38
jj_tui/lib/debounce.ml
··· 1 + open Picos_std_structured 2 + 3 + type 'a t = { 4 + delay : float 5 + ; merge : 'a -> 'a -> 'a 6 + ; run : 'a -> unit 7 + ; pending : 'a option ref 8 + ; debounce_computation : unit Promise.t ref 9 + ; current_computation : unit Promise.t ref 10 + } 11 + 12 + let make ~delay ~merge ~run () = 13 + { 14 + delay 15 + ; merge 16 + ; run 17 + ; pending = ref None 18 + ; debounce_computation = ref (Promise.of_value ()) 19 + ; current_computation = ref (Promise.of_value ()) 20 + } 21 + ;; 22 + 23 + let push t value = 24 + t.pending 25 + := Some 26 + (match !(t.pending) with None -> value | Some pending -> t.merge pending value); 27 + Promise.terminate !(t.debounce_computation); 28 + t.debounce_computation 29 + := Flock.fork_as_promise (fun () -> 30 + Control.sleep ~seconds:t.delay; 31 + match !(t.pending) with 32 + | None -> 33 + () 34 + | Some pending -> 35 + t.pending := None; 36 + Promise.terminate !(t.current_computation); 37 + t.current_computation := Flock.fork_as_promise (fun () -> t.run pending)) 38 + ;;