Skip to content

Commit

Permalink
Fix suspended fiber reference being null during destruction
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Mar 4, 2022
1 parent 13ca2ba commit 0ea6f60
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/EventLoop/Internal/DriverSuspension.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ public function resume(mixed $value = null): void

$this->pending = false;

if ($this->suspendedFiber) {
($this->queue)(\Closure::fromCallable([$this->suspendedFiber, 'resume']), $value);
/** @var \Fiber|null $fiber */
$fiber = $this->fiberRef?->get();

if ($fiber) {
($this->queue)(\Closure::fromCallable([$fiber, 'resume']), $value);
} else {
// Suspend event loop fiber to {main}.
($this->interrupt)(static fn () => $value);
Expand Down Expand Up @@ -132,8 +135,11 @@ public function throw(\Throwable $throwable): void

$this->pending = false;

if ($this->suspendedFiber) {
($this->queue)(\Closure::fromCallable([$this->suspendedFiber, 'throw']), $throwable);
/** @var \Fiber|null $fiber */
$fiber = $this->fiberRef?->get();

if ($fiber) {
($this->queue)(\Closure::fromCallable([$fiber, 'throw']), $throwable);
} else {
// Suspend event loop fiber to {main}.
($this->interrupt)(static fn () => throw $throwable);
Expand Down

0 comments on commit 0ea6f60

Please sign in to comment.