The queue_foreach() function always returns success, even if one of
the callbacks failed. This makes it hard to handle errors that occur
inside the callbacks.
This commit changes the function to return failure if a callback has
failed.
local data
local mutex
local item
+ local err
data=$(_queue_get_data "$name")
mutex=$(_queue_get_mutex "$name")
+ err=0
if ! mutex_lock "$mutex"; then
return 1
if [ -f "$data" ]; then
while read -r item; do
if ! "$func" "$item" "${args[@]}"; then
+ err=1
break
fi
done < "$data"
mutex_unlock "$mutex"
- return 0
+ return "$err"
}