7

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 (async-start ;; What to do in the child process (lambda () (message "This is a test") (sleep-for 3) 222) ;; What to do when it finishes (lambda (result) (format "Async process done - result should be 222: %s" result))) #+end_src #+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?

6
  • 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". Commented Oct 21, 2014 at 19:39
  • @mankoff: OK I've re-worded and simplified the question to try an make it easier to follow. Is that better? Commented Oct 22, 2014 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? Commented Oct 22, 2014 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. Commented Oct 22, 2014 at 14:22
  • @mankoff: How's the new elisp only example? Commented Oct 22, 2014 at 14:34

1 Answer 1

4

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" (async-start ;; 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") (list (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)))) (save-excursion (with-current-buffer buf (org-babel-goto-named-result name) (next-line) (goto-char (org-babel-result-end)) (org-babel-insert-result (format "we got: %s" res))))))) #+end_src #+RESULTS: simple-async-with-post-modify : #<process emacs> : we got: 222 
1
  • 1
    Hi. There is a post by John Kitchin discussing a prototype solution for python code blocks that might be interesting to you. Commented Mar 1, 2016 at 6:04

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.