28.3 Asynchronous Runner Example

Here’s a simple example in Bash:

#!/bin/bash

# well, treat me like a slow task
sleep 5
echo "now I'm done."

Say, you have a controller in your webapp:

(import (artanis runner)
        (artanis cli))

(get "/run"
  (lambda (rc)
    (call-with-runner
     (lambda ()
       (cli-run* bash /dev/shm/run.sh)))))

You may visit the controller:

curl localhost:3000/run
# wait for 6 seconds then get:
now I'm done.