Skip to content

Commit a928073

Browse files
committed
Unwrap exception only if suspended by interrupt
There are also situations where the event loop simply terminates.
1 parent e4bc85e commit a928073

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/EventLoop/Internal/DriverSuspension.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,16 @@ public function suspend(): mixed
7777
}
7878

7979
// Awaiting from {main}.
80-
$result = ($this->run)()();
80+
$result = ($this->run)();
8181

8282
/** @psalm-suppress RedundantCondition $this->pending should be changed when resumed. */
8383
if ($this->pending) {
84-
// Should only be true if the event loop exited without resolving the promise.
85-
throw new \Error('Scheduler suspended or exited unexpectedly');
84+
$result && $result(); // Unwrap any uncaught exceptions from the event loop
85+
86+
throw new \Error('Event loop terminated without resuming the current suspension');
8687
}
8788

88-
return $result;
89+
return $result();
8990
}
9091

9192
public function throw(\Throwable $throwable): void

0 commit comments

Comments
 (0)