/** * Wait for the processes started via call(). * * @param int $pid The pid to wait for, if none is passed then all threads created by this object will be waited for * * @return void */ public function wait($pid = null) { if ($pid) { $threads = [$pid]; } else { $threads = $this->threads; } $error = 0; $status = 0; foreach ($threads as $pid) { $status = $this->adapter->wait($pid); if ($status > 0) { $error = $status; } unset($this->threads[$pid]); } # If no errors occured then we're done if ($error === 0) { return; } $exceptions = $this->adapter->getExceptions(); $message = "An error occurred within a thread, the return code was: {$error}\n"; foreach ($exceptions as $exception) { $message .= " - {$exception}\n"; } throw new Exception($message, $error); }