guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch master updated: progress: Rate limit drawing in the progress-repo


From: guix-commits
Subject: branch master updated: progress: Rate limit drawing in the progress-reporter/bar.
Date: Sun, 12 Dec 2021 10:23:13 -0500

This is an automated email from the git hooks/post-receive script.

cbaines pushed a commit to branch master
in repository guix.

The following commit(s) were added to refs/heads/master by this push:
     new 604880a  progress: Rate limit drawing in the progress-reporter/bar.
604880a is described below

commit 604880ae22e1a7662acb1d3f282242470de0cd03
Author: Christopher Baines <mail@cbaines.net>
AuthorDate: Fri Sep 17 11:15:56 2021 +0100

    progress: Rate limit drawing in the progress-reporter/bar.
    
    This helps smooth the output in cases where the bar is updated very quickly,
    for example in guix weather where it's computing derivations.
    
    * guix/progress.scm (progress-reporter/bar): Wrap the drawing code with the
    rate-limited procedure.
---
 guix/progress.scm | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/guix/progress.scm b/guix/progress.scm
index 0cbc804..4f8e98e 100644
--- a/guix/progress.scm
+++ b/guix/progress.scm
@@ -270,19 +270,25 @@ ABBREVIATION used to shorten FILE for display."
 tasks is performed.  Write PREFIX at the beginning of the line."
   (define done 0)
 
+  (define (draw-bar)
+    (let* ((ratio (* 100. (/ done total))))
+      (erase-current-line port)
+      (if (string-null? prefix)
+          (display (progress-bar ratio (current-terminal-columns)) port)
+          (let ((width (- (current-terminal-columns)
+                          (string-length prefix) 3)))
+            (display prefix port)
+            (display "  " port)
+            (display (progress-bar ratio width) port)))
+      (force-output port)))
+
+  (define draw-bar/rate-limited
+    (rate-limited draw-bar %progress-interval))
+
   (define (report-progress)
     (set! done (+ 1 done))
     (unless (> done total)
-      (let* ((ratio (* 100. (/ done total))))
-        (erase-current-line port)
-        (if (string-null? prefix)
-            (display (progress-bar ratio (current-terminal-columns)) port)
-            (let ((width (- (current-terminal-columns)
-                            (string-length prefix) 3)))
-              (display prefix port)
-              (display "  " port)
-              (display (progress-bar ratio width) port)))
-        (force-output port))))
+      (draw-bar/rate-limited)))
 
   (progress-reporter
    (start (lambda ()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]