Skip to content

Commit e4bc85e

Browse files
authored
Always rethrow errors in DriverSuspension (#31)
1 parent 498362a commit e4bc85e

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/EventLoop/Internal/DriverSuspension.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ public function suspend(): mixed
7777
}
7878

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

8282
/** @psalm-suppress RedundantCondition $this->pending should be changed when resumed. */
8383
if ($this->pending) {
8484
// Should only be true if the event loop exited without resolving the promise.
8585
throw new \Error('Scheduler suspended or exited unexpectedly');
8686
}
8787

88-
return $lambda();
88+
return $result;
8989
}
9090

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

test/EventLoopTest.php

+14
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,18 @@ public function testSuspensionWithinQueue(): void
197197

198198
self::assertSame($send, $received);
199199
}
200+
201+
public function testSuspensionThrowingErrorViaInterrupt(): void
202+
{
203+
$suspension = EventLoop::createSuspension();
204+
$error = new \Error("Test error");
205+
EventLoop::queue(static fn () => throw $error);
206+
EventLoop::defer(static fn () => $suspension->resume("Value"));
207+
try {
208+
$suspension->suspend();
209+
self::fail("Error was not thrown");
210+
} catch (\Throwable $t) {
211+
self::assertSame($error, $t);
212+
}
213+
}
200214
}

0 commit comments

Comments
 (0)