grokking simplicity and refactoring
This commit is contained in:
parent
89a7fe100d
commit
fb4361d938
67 changed files with 6275 additions and 56 deletions
27
packages/lab-tool/utils/logging/spinner.scm
Normal file
27
packages/lab-tool/utils/logging/spinner.scm
Normal file
|
@ -0,0 +1,27 @@
|
|||
;; utils/logging/spinner.scm - Spinner utility for long operations
|
||||
|
||||
(define-module (utils logging spinner)
|
||||
#:use-module (utils logging core)
|
||||
#:export (with-spinner))
|
||||
|
||||
;; Pure function: Calculate elapsed time
|
||||
;; Input: start-time, end-time
|
||||
;; Output: elapsed seconds
|
||||
(define (calculate-elapsed start-time end-time)
|
||||
"Pure function to calculate elapsed time"
|
||||
(- end-time start-time))
|
||||
|
||||
;; Impure function: Execute operation with spinner logging
|
||||
(define (with-spinner message thunk)
|
||||
"Execute operation with progress logging"
|
||||
(log-info "~a..." message)
|
||||
(let ((start-time (current-time)))
|
||||
(catch #t
|
||||
(lambda ()
|
||||
(let ((result (thunk)))
|
||||
(let ((elapsed (calculate-elapsed start-time (current-time))))
|
||||
(log-success "~a completed in ~as" message elapsed))
|
||||
result))
|
||||
(lambda (key . args)
|
||||
(log-error "~a failed: ~a ~a" message key args)
|
||||
(throw key args)))))
|
Loading…
Add table
Add a link
Reference in a new issue