Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Nov 16, 2023
1 parent a8b99c0 commit 75355e6
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/EventLoop/Internal/DriverSuspension.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ public function suspend(): mixed
{
// Throw exception when trying to use old dead {main} suspension
if ($this->deadMain) {
\assert($this->error !== null);
throw $this->error;
throw new \Error(
'Suspension cannot be suspended after an uncaught exception is thrown from the event loop',
);
}
if ($this->pending) {
throw new \Error('Must call resume() or throw() before calling suspend() again');
Expand Down Expand Up @@ -116,15 +117,7 @@ public function suspend(): mixed
// This is now a dead {main} suspension.
$this->deadMain = true;

try {
$result && $result(); // Unwrap any uncaught exceptions from the event loop
} catch (\Throwable $throwable) {
$this->error = new \Error(
'Suspension cannot be suspended after an uncaught exception is thrown from the event loop',
);

throw $throwable;
}
$result && $result(); // Unwrap any uncaught exceptions from the event loop

\gc_collect_cycles(); // Collect any circular references before dumping pending suspensions.

Expand All @@ -142,7 +135,7 @@ public function suspend(): mixed
}
}

throw $this->error = new \Error('Event loop terminated without resuming the current suspension (the cause is either a fiber deadlock, or an incorrectly unreferenced/canceled watcher):' . $info);
throw new \Error('Event loop terminated without resuming the current suspension (the cause is either a fiber deadlock, or an incorrectly unreferenced/canceled watcher):' . $info);
}

return $result();
Expand Down

0 comments on commit 75355e6

Please sign in to comment.