Shell: How do I make sure only one command duplicate will be executed after the current one

I am watching my project dir for the file change and running sync script whenever files change.

Certainly I do not want to run the second synchronization before the first one is done. flock utility seems to be fit for preventing second sync from running as in

fswatch -0 ./myproject | xargs -0 -n 1 "flock /tmp/my.lock ./container_update.sh


However, it just puts the next request to the waiting queue, so if I change 20 small files, twenty synchronization will be run. That can be solved with flock -n that would quit immediately if lock cannot be obtained, but then I will lose changes performed while sync is in progress.

I tried building a naive single slot queue with a new item first requesting a "queue" lock, then proceeding to the "main" lock, leaving the "queue" one free for one more request only. It doesn't help; change requests continue to pile.

fswatch ./myproject | xargs -0 -n 1 "flock -n /tmp/my-queue.lock flock /tmp/my-main.lock flock -u /tmp/my-queue.lock ./container_update.sh"

What would be a way to let only one "next" request to be executed?

P.S. If it matters I am running it on a Mac with this implementation of flock that is supposed to be identical to the Linux one - https://github.com/discoteq/flock