I'm currently experimenting with moving more of my development workflow into org-mode so I can keep better track of what testing I've done. However some of the steps involve asynchronous calls to RPC services. The following snippet shows the problem:

#+name: simple-async-example
#+begin_src emacs-lisp 
     ;; What to do in the child process
     (lambda ()
       (message "This is a test")
       (sleep-for 3)

     ;; What to do when it finishes
     (lambda (result)
       (format "Async process done - result should be 222: %s" result)))

#+RESULTS: simple-async-example
: #<process emacs>

As you can see the result comes from the first task. What I need to do is append the actual result once the processing has been completed. Is there any way to achieve this?

  • 1
    Apart from the title, it isn't actually clear what your question is. Answering the title, I think this question comes up often on the Org email list, and the answer is "not currently supported". – mankoff Oct 21 '14 at 19:39
  • @mankoff: OK I've re-worded and simplified the question to try an make it easier to follow. Is that better? – stsquad Oct 22 '14 at 9:05
  • en.wikipedia.org/wiki/Minimal_Working_Example why not have a 3-line bash script that returns something asynch that anyone can run/test/understand? – mankoff Oct 22 '14 at 13:52
  • @mankoff: well bash is inherently synchronous isn't it? I did wrap all the build and upload stuff into one script to simplify it but the LAVA job submission is something that happens asynchronously within emacs. – stsquad Oct 22 '14 at 14:22
  • @mankoff: How's the new elisp only example? – stsquad Oct 22 '14 at 14:34

OK Solving for the (async) example I've come up with this hack. It would be nice if I could automatically get the name of the source block rather than having to repeat it as a var.

** Post-modify the org-result
#+name: simple-async-with-post-modify
#+begin_src emacs-lisp :var this-buffer=(buffer-name (current-buffer)) this-name="simple-async-with-post-modify"
     ;; What to do in the child process
   `(lambda ()
     (message "This is a test")
     (sleep-for 3)
     ,(async-inject-variables "this-buffer")
     ,(async-inject-variables "this-name")
        (cons 'buffer this-buffer)
        (cons 'name this-name)
        (cons 'result 222)))

     ;; What to do when it finishes
   (lambda (result)
     (let ((buf (cdr (assoc 'buffer result)))
           (name (cdr (assoc 'name result)))
           (res (cdr (assoc 'result result))))
         (with-current-buffer buf
           (org-babel-goto-named-result name)
           (goto-char (org-babel-result-end))
           (org-babel-insert-result (format "we got: %s" res)))))))

#+RESULTS: simple-async-with-post-modify
: #<process emacs>
: we got: 222
  • 1
    Hi. There is a post by John Kitchin discussing a prototype solution for python code blocks that might be interesting to you. – dfeich Mar 1 '16 at 6:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.