Hey, scripter! Need to make your Bash functions play nice in the concurrency sandbox? You're in luck!
with_lock
is your go-to decorator. It ensures specified functions run one at a time, even across multiple script instances. 🤖
- It's mostly FIFO (first in, first out), but occasionally things get a bit mixed. 🤷♀️
- Know a better way? Share it!
🚀 Before launching, note that this is bash-specific and assumes you're on MacOS (brew) or Debian/Ubuntu (apt). It's not a multitasking Swiss Army knife; it's your queue-forming buddy.
chmod +x {with_lock,test_harness.sh}
./test_harness.sh
_my_func() {
# Your logic here
}
my_func() {
with_lock _my_func "$@"
}
# Run without worrying about overlap!
my_func "arg1" "arg2"
Try it out and let us know what you think! 🌟
This is just created! It has not been thoroughly tested, but it's the basis for something more. For some stuff it's enough as it is.
Improvements welcome!