Skip to content

Commit

Permalink
chore(io): cleanup internal resource handle
Browse files Browse the repository at this point in the history
Signed-off-by: azjezz <azjezz@protonmail.com>
  • Loading branch information
azjezz committed Jan 14, 2022
1 parent 13ed46c commit 2bc1d76
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Psl/IO/Internal/ResourceHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Revolt\EventLoop\Suspension;

use function array_shift;
use function array_slice;
use function error_get_last;
use function fclose;
use function fseek;
Expand Down Expand Up @@ -359,11 +358,16 @@ public function close(): void
$this->stream = null;
}

$this->readSuspension?->throw(new Exception\AlreadyClosedException('Handle has already been closed.'));
$exception = new Exception\AlreadyClosedException('Handle has already been closed.');
$suspensions = [$this->readSuspension, $this->writeSuspension, ...$this->readQueue, ...$this->writeQueue];
$this->readSuspension = null;

$this->writeSuspension?->throw(new Exception\AlreadyClosedException('Handle has already been closed.'));
$this->writeSuspension = null;
$this->writeQueue = [];
$this->readQueue = [];

foreach ($suspensions as $suspension) {
$suspension?->throw($exception);
}
}
}
}

0 comments on commit 2bc1d76

Please sign in to comment.