Skip to content

Instantly share code, notes, and snippets.

@nicferrier
Created February 15, 2013 20:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicferrier/4963129 to your computer and use it in GitHub Desktop.
Save nicferrier/4963129 to your computer and use it in GitHub Desktop.
sentinel based cps in emacs-lisp. bit wierd
(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