Skip to content

marciol/bash_async_tasks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bash_async_tasks

Small helper functions to run tasks async on Bash

This lib provides 3 primitives to help run functions on bash asynchronously:

task_start task_run task_wait

This is an example get from tasks/example.sh

__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

regular_task() {
  echo "$@"
  sleep $(echo $RANDOM % 10 + 1 | bc)
  echo "This message is from ${0}"
}

run() {
  echo "${CYAN}* Run regular_task Multiple times...${NORMAL}"

  task_start

  for i in {0..10}; do
    cmd=(regular_task ${i} "from regular task")
    task_run cmd[@]
  done

  task_wait
}

run

The logged output is prefixed with the pid that is running the task.

This should produce an output as showed bellow:

screenshot of simple running example

About

Small helper functions to run tasks async on Bash

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages