@Jan
if (!$stat[0]) // the job is known so it is not done
I believe to be correct. I read it as, if $stat[0] returns anything but false, the job is currently running, so we are not done. However, if we cannot find $stat[0] (ie: the job handle no longer exists) then the job is done.
--Richard