Created
February 15, 2013 20:08
-
-
Save nicferrier/4963129 to your computer and use it in GitHub Desktop.
sentinel based cps in emacs-lisp. bit wierd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun cps-foreach-bg (proc l cont &optional command-args) | |
"Call PROC with each element of L, in the background. | |
When there are no more elements of L call CONT with L. | |
Optionally use the COMMAND-ARGS as the command to run in the | |
operating system to do the queueing." | |
(let* ((process-args (or command-args '("sleep" "1"))) | |
(qproc (apply | |
'start-process | |
"queue" (get-buffer-create "*queue*") | |
process-args))) | |
(set-process-sentinel | |
qproc | |
(lambda (process status) | |
(when (string-match ".*finished\n" status) | |
(if l | |
(funcall | |
proc (car l) | |
(lambda (a) (cps-foreach-bg proc (cdr l) cont))) | |
;; Else | |
(funcall cont l))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment