because I can’t imagine why you would want to pop the last element off of an array if any element in it equals '2.
Don't try to analyze code logic. It's a proof-of-concept code. Perl does not care about it's logic
when execute it, so you should not too.
clarity
So, if don't wish to see proof-of-concept code without any sane logic, perhaps you want to see real code,
here it is.
do_finish() removes element from @{$self->{jobs_a}}, after that we exit "for" loop in get_task().
Do you think it will be more clear if it will return number of element to remove, and we remove it outside for loop?