branch: externals/el-job
commit b01324750d11ff7c7a6998dba9b15b15aeded8a2
Author: Martin Edström <meedstro...@gmail.com>
Commit: Martin Edström <meedstro...@gmail.com>

    .
---
 .github/workflows/melpazoid.yml |  2 +-
 README.org                      |  8 ++++++--
 el-job.el                       | 34 ++++++++++++++++++++++------------
 3 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/.github/workflows/melpazoid.yml b/.github/workflows/melpazoid.yml
index 76e1f7065c..e7f80a5996 100644
--- a/.github/workflows/melpazoid.yml
+++ b/.github/workflows/melpazoid.yml
@@ -25,7 +25,7 @@ jobs:
       env:
         LOCAL_REPO: ${{ github.workspace }}
         # RECIPE is your recipe as written for MELPA:
-        RECIPE: (shx :repo "riscy/shx-for-emacs" :fetcher github)
+        RECIPE: (el-job :repo "meedstrom/el-job" :fetcher github)
         # set this to false (or remove it) if the package isn't on MELPA:
         EXIST_OK: true
       run: echo $GITHUB_REF && make -C ~/melpazoid
diff --git a/README.org b/README.org
index eb74ae7e75..22434f51b7 100644
--- a/README.org
+++ b/README.org
@@ -1,7 +1,11 @@
 
 Imagine you have a function you'd like to run on a long list of inputs.  You 
could run =(mapcar #'FN INPUTS)=, but that hangs Emacs until done.
 
-This library gives you the tools to split up the inputs and run the function 
in many subprocesses (one per core), then merges their outputs and passes it 
back to the current Emacs.  In the meantime, current Emacs does not hang at all.
+This library gives you the tools to split up the inputs and run the function 
in many subprocesses (one per CPU core), then merges their outputs and passes 
it back to the current Emacs.  In the meantime, current Emacs does not hang at 
all.
 
 
-# For now, some limitations on the return values.
+-------
+
+For real-world usage, search for =el-job-launch= in the source of 
[[https://github.com/meedstrom/org-node/blob/use-el-job/org-node.el][org-node.el]].
+
+For now, some limitations on FN's return value, which must always be a list of 
a fixed length, where the elements are themselves lists.
diff --git a/el-job.el b/el-job.el
index 27b30bff08..8bf92666c4 100644
--- a/el-job.el
+++ b/el-job.el
@@ -18,17 +18,28 @@
 ;; Author:           Martin Edström <meedstro...@gmail.com>
 ;; Created:          2024-10-30
 ;; Keywords:         processes
-;; Package-Requires: ((emacs "28.1") (compat "30"))
 ;; URL:              https://github.com/meedstrom/el-job
+;; Package-Requires: ((emacs "28.1") (compat "30"))
 
 ;;; Commentary:
 
+;; Imagine you have a function you'd like to run on a long list of inputs.  You
+;; could run (mapcar #'FN INPUTS), but that hangs Emacs until done.
+
+;; This library gives you the tools to split up the inputs and run the function
+;; in many subprocesses (one per CPU core), then merges their outputs and
+;; passes it back to the current Emacs.  In the meantime, current Emacs does
+;; not hang at all.
+
+;; The only public API is the function `el-job-launch'.
+
 ;;; Code:
 
 (require 'cl-lib)
 (require 'esh-proc)
 (require 'compat)
 (require 'el-job-child)
+(declare-function eshell-wait-for-processes "esh-proc")
 
 ;;; Subroutines:
 
@@ -210,9 +221,8 @@ each element is wrapped in its own list."
         (setq big-list (nthcdr sublist-length big-list))))
     (delq nil result)))
 
-(defcustom el-job-cores nil
-  "Max simultaneous processes for a given batch of jobs."
-  :type '(choice integer (const nil)))
+(defvar el-job-force-cores nil
+  "Max simultaneous processes for a given batch of jobs.")
 
 (defvar el-job--cores nil
   "Max simultaneous processes for a given batch of jobs.")
@@ -269,7 +279,7 @@ See `el-job-child--zip' for details."
                               lock
                               ;; use-file-handlers
                               debug ;; TODO
-                              max-jobs ;; TODO
+                              max-cores ;; TODO
                               )
   "Run FUNCALL in one or more headless Elisp processes.
 Then merge the return values \(lists of N lists) into one list
@@ -345,11 +355,12 @@ child before it loads anything else."
   (unless (symbolp funcall)
     (error "Argument :funcall only takes a symbol"))
   (setq load (ensure-list load))
-  (if el-job-cores
-      (setq el-job--cores el-job-cores)
+  (if el-job-force-cores
+      (setq el-job--cores el-job-force-cores)
     (unless el-job--cores
       (setq el-job--cores (el-job--count-logical-cores))))
-  (let (batch stop)
+  (let ((n-jobs (or max-cores el-job--cores))
+        batch stop )
     (if lock
         (if (setq batch (gethash lock el-job--batches))
             (if (seq-some #'process-live-p (el-job-processes batch))
@@ -384,10 +395,9 @@ child before it loads anything else."
      (t
       (with-current-buffer (get-buffer-create (el-job-stderr batch) t)
         (erase-buffer))
-      (let* ((splits
-              (el-job--split-optimally inputs
-                                       el-job--cores
-                                       (el-job-elapsed-table batch)))
+      (let* ((splits (el-job--split-optimally inputs
+                                              max-cores
+                                              (el-job-elapsed-table batch)))
              (n (if splits (length splits) 1))
              (inject-vars-alist
               (cons (cons 'current-time-list current-time-list)

Reply via email to