1
0
mirror of https://github.com/danog/parallel.git synced 2024-11-30 04:39:01 +01:00

Remove unnecessary try/catch

execute() will never throw, so no reason to wrap in try/catch.
This commit is contained in:
Aaron Piotrowski 2017-07-19 00:08:55 -05:00
parent bba0610ede
commit 58ce0df037
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB
2 changed files with 13 additions and 28 deletions

View File

@ -176,18 +176,12 @@ class Fork implements Process, Strand {
// @codeCoverageIgnoreStart
\fclose($child);
try {
Loop::set((new Loop\DriverFactory)->create()); // Replace loop instance inherited from parent.
Loop::run(function () use ($parent) {
$channel = new ChannelledSocket($parent, $parent, false);
return $this->execute($channel);
});
$code = 0;
} catch (\Throwable $exception) {
$code = 1;
}
Loop::set((new Loop\DriverFactory)->create()); // Replace loop instance inherited from parent.
Loop::run(function () use ($parent) {
return $this->execute(new ChannelledSocket($parent, $parent));
});
exit($code);
exit(0);
// @codeCoverageIgnoreEnd
default: // Parent
$this->pid = $pid;

View File

@ -82,25 +82,16 @@ class Thread extends \Thread {
// At this point, the thread environment has been prepared so begin using the thread.
try {
Loop::run(function () {
$channel = new ChannelledSocket($this->socket, $this->socket, false);
$watcher = Loop::repeat(self::KILL_CHECK_FREQUENCY, function () {
if ($this->killed) {
Loop::stop();
}
});
Loop::unreference($watcher);
return $this->execute($channel);
Loop::run(function () {
$watcher = Loop::repeat(self::KILL_CHECK_FREQUENCY, function () {
if ($this->killed) {
Loop::stop();
}
});
} catch (\Throwable $exception) {
return 1;
}
Loop::unreference($watcher);
return 0;
return $this->execute(new ChannelledSocket($this->socket, $this->socket));
});
}
/**