emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/el-job 5c82684afb 2/5: Don't run with nil input, return


From: ELPA Syncer
Subject: [elpa] externals/el-job 5c82684afb 2/5: Don't run with nil input, return special value instead
Date: Tue, 25 Mar 2025 18:58:14 -0400 (EDT)

branch: externals/el-job
commit 5c82684afb03cbf3e817647edc3d46d12792fa39
Author: Martin Edström <meedstrom@runbox.eu>
Commit: Martin Edström <meedstrom@runbox.eu>

    Don't run with nil input, return special value instead
---
 el-job-child.el | 21 ++++++++-------------
 el-job.el       | 52 ++++++++++++++++++++++++++++------------------------
 2 files changed, 36 insertions(+), 37 deletions(-)

diff --git a/el-job-child.el b/el-job-child.el
index 849ad7e32f..0277dab824 100644
--- a/el-job-child.el
+++ b/el-job-child.el
@@ -63,19 +63,14 @@ add that information to the final return value."
         (let (item start output metadata results)
           (when (eq input 'die)
             (throw 'die nil))
-          (if input
-              (while input
-                (setq item (pop input))
-                (setq start (current-time))
-                (setq output (funcall func item))
-                (push (time-since start) metadata)
-                (setq results (el-job-child--zip output results)))
-            ;; A job with nil input.
-            ;; We are the sole subprocess, and we call :funcall-per-inputs
-            ;; a grand total of once, presumably for side effects.
-            ;; REVIEW: Is it even worth keeping this code path?
-            ;;         Probably not.
-            (funcall func nil))
+          (unless input
+            (error "Input must be non-nil"))
+          (while input
+            (setq item (pop input))
+            (setq start (current-time))
+            (setq output (funcall func item))
+            (push (time-since start) metadata)
+            (setq results (el-job-child--zip output results)))
           ;; Ensure the benchmarks are in same order that ITEMS came in,
           ;; letting us associate which with which just by index.
           (setq metadata (nreverse metadata))
diff --git a/el-job.el b/el-job.el
index efe5f4b91b..389067c375 100644
--- a/el-job.el
+++ b/el-job.el
@@ -378,11 +378,13 @@ process that locates files \(by inspecting 
`load-history', via
 
 INPUTS is a list that will be split by up to the output of
 `num-processors', and this determines how many subprocesses will spawn.
-If INPUTS is omitted, only one subprocess will spawn.
 
 INPUTS can also be a function that returns a list.  In this case, the
 function is deferred until needed, possibly saving on compute.
 
+If INPUTS returns nil, do nothing and return the symbol
+`inputs-were-empty'.
+
 
 The subprocesses have no access to current Emacs state.  The only way
 they can affect current state, is if FUNCALL-PER-INPUT returns data,
@@ -451,29 +453,31 @@ For debugging, see these commands:
               ('wait (setf .queued-inputs (append inputs .queued-inputs))))
           (setf .queued-inputs inputs)
           (setq do-exec t))
-        (when do-exec
-          (setf .callback callback)
-          ;; Prevent spawning a dozen processes when you'll use only one or two
-          (let ((machine-cores (max 1 (1- (num-processors)))))
-            (setf .n-cores-to-use (if (length< .queued-inputs machine-cores)
-                                      (length .queued-inputs)
-                                    machine-cores))
-            (when (or (length< .ready .n-cores-to-use)
-                      (not (cl-every #'process-live-p .ready)))
-              (setq do-respawn t)))
-          (let ((new-spawn-args (list job
-                                      load-features
-                                      inject-vars
-                                      funcall-per-input)))
-            (unless (= (sxhash (cdr .spawn-args))
-                       (sxhash (cdr new-spawn-args)))
-              (setf .spawn-args new-spawn-args)
-              (el-job--dbg 2 "New arguments, resetting processes for %s" id)
-              (setq do-respawn t)))
-          (when do-respawn
-            (el-job--disable job)
-            (apply #'el-job--spawn-processes .spawn-args))
-          (el-job--exec-workload job))))))
+        (if (null .queued-inputs)
+            'inputs-were-empty
+          (when do-exec
+            (setf .callback callback)
+            ;; Prevent spawning a dozen processes when we need only one or two
+            (let ((machine-cores (max 1 (1- (num-processors)))))
+              (setf .n-cores-to-use (if (length< .queued-inputs machine-cores)
+                                        (length .queued-inputs)
+                                      machine-cores))
+              (when (or (length< .ready .n-cores-to-use)
+                        (not (cl-every #'process-live-p .ready)))
+                (setq do-respawn t)))
+            (let ((new-spawn-args (list job
+                                        load-features
+                                        inject-vars
+                                        funcall-per-input)))
+              (unless (= (sxhash (cdr .spawn-args))
+                         (sxhash (cdr new-spawn-args)))
+                (setf .spawn-args new-spawn-args)
+                (el-job--dbg 2 "New arguments, resetting processes for %s" id)
+                (setq do-respawn t)))
+            (when do-respawn
+              (el-job--disable job)
+              (apply #'el-job--spawn-processes .spawn-args))
+            (el-job--exec-workload job)))))))
 
 (defvar-local el-job-here nil)
 (defun el-job--spawn-processes (job load-features inject-vars 
funcall-per-input)



reply via email to

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