Skip to content

Instantly share code, notes, and snippets.

@hh
Last active July 28, 2022 16:37
Show Gist options
  • Save hh/02918b1d5732a61ae845e48888c8d73c to your computer and use it in GitHub Desktop.
Save hh/02918b1d5732a61ae845e48888c8d73c to your computer and use it in GitHub Desktop.
async vs sync

:async vs :sync Execution

We’ll use `org-babel-execute-subtree` bound to C-c C-v s by default to run the following two headings.

# let's make an STDERR here
echo THIS ISNT JSON | jq .

:sync t

These code blocks will run one after another. Also, while running, emacs will be frozen / blocked. So this will take about 10 seconds.

sleep 5

We can also add :sync t as a beginsrc code block argument. Though it is the default, AND is set in our inherited PROPERTIES drawer.

date
sleep 5
date

nosleep

date

sleep 1

date
sleep 1
date

sleep 3

date
sleep 3
date

sleep 2

date
sleep 2
date

:async t

These code blocks will start almost at the same time, and run in the background.

sleep 5

We can also add :async t as a beginsrc code block argument. Though it is the default

date
sleep 5
date
Thu Jul 28 10:31:23 AM MDT 2022
Thu Jul 28 10:31:28 AM MDT 2022

no sleep

date
Thu Jul 28 10:31:23 AM MDT 2022

sleep 1

date
sleep 1
date
Thu Jul 28 10:31:23 AM MDT 2022
Thu Jul 28 10:31:24 AM MDT 2022

sleep 3

date
sleep 3
date
Thu Jul 28 10:31:23 AM MDT 2022
Thu Jul 28 10:31:26 AM MDT 2022

sleep 2

date
sleep 2
date
Thu Jul 28 10:31:23 AM MDT 2022
Thu Jul 28 10:31:25 AM MDT 2022

Footer

Tangling result block vi :wrap argument

#+name jsonstuff

kubectl get node ii-control-plane-pmscp -o json  | jq .metadata.annotations

named code block + var/parameters

sleep

date
echo Sleeping $seconds seconds
sleep $seconds
date

sleep longer

Thu Jul 28 10:04:18 AM MDT 2022
Sleeping 2 seconds
Thu Jul 28 10:04:20 AM MDT 2022

inline code blocks seem to still be broken

f1b42636d3a2457759d0b8b56aab8e23

Also results in No org-babel-execute function for nosleep! messages.

Maybe due to the way ob-async spawn another emacs… without the context of this buffer and it’s other named code blocks. OR something else I’m missing.

adding :async to the end… no async

Thu Jul 28 09:48:31 AM MDT 2022
Sleeping 1 seconds
Thu Jul 28 09:48:32 AM MDT 2022

adding :async to the call… still no async

Thu Jul 28 09:48:46 AM MDT 2022
Sleeping 2 seconds
Thu Jul 28 09:48:48 AM MDT 2022

Async

:async vs :sync Execution

We’ll use `org-babel-execute-subtree` bound to C-c C-v s by default to run the following two headings.

:sync t

These code blocks will run one after another. Also, while running, emacs will be frozen / blocked. So this will take about 10 seconds.

sleep 5

We can also add :sync t as a begin_src code block argument. Though it is the default, AND is set in our inherited PROPERTIES drawer.

date
sleep 5
date

nosleep

date

sleep 1

date
sleep 1
date

sleep 3

date
sleep 3
date

sleep 2

date
sleep 2
date

:async t

These code blocks will start almost at the same time, and run in the background.

sleep 5

We can also add :async t as a begin_src code block argument. Though it is the default

date
sleep 5
date

no sleep

date

sleep 1

date
sleep 1
date

sleep 3

date
sleep 3
date

sleep 2

date
sleep 2
date

Footer

named code block + var/parameters

sleep

date
echo Sleeping $seconds seconds
sleep $seconds
date

sleep longer

inline code blocks seem to still be broken

src_nosleep[:sync t]{} src_nosleep[:async t]{} {{{results(f1b42636d3a2457759d0b8b56aab8e23)}}} Also results in No org-babel-execute function for nosleep!. Maybe due to the way ob-async spawn another emacs… without the context of this buffer and it’s other named code blocks. OR something else I’m missing.

adding :async to the end… no async

adding :async to the call… still no async

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment