Skip to content

Commit

Permalink
Performance optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
walkor committed Sep 3, 2024
1 parent 6274c34 commit 1d25e3f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/Events/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function repeat(float $interval, callable $func, array $args = []): int
{
$className = $this->eventClassName;
$timerId = $this->timerId++;
$event = new $className($this->eventBase, -1, $className::TIMEOUT | $className::PERSIST, fn () => $this->safeCall($func, $args));
$event = new $className($this->eventBase, -1, $className::TIMEOUT | $className::PERSIST, $func);
if (!$event->addTimer($interval)) {
throw new \RuntimeException("Event::addTimer($interval) failed");
}
Expand All @@ -155,7 +155,7 @@ public function onReadable($stream, callable $func): void
{
$className = $this->eventClassName;
$fdKey = (int)$stream;
$event = new $className($this->eventBase, $stream, $className::READ | $className::PERSIST, fn () => $this->safeCall($func, [$stream]));
$event = new $className($this->eventBase, $stream, $className::READ | $className::PERSIST, $func);
if ($event->add()) {
$this->readEvents[$fdKey] = $event;
}
Expand All @@ -182,7 +182,7 @@ public function onWritable($stream, callable $func): void
{
$className = $this->eventClassName;
$fdKey = (int)$stream;
$event = new $className($this->eventBase, $stream, $className::WRITE | $className::PERSIST, fn () => $this->safeCall($func, [$stream]));
$event = new $className($this->eventBase, $stream, $className::WRITE | $className::PERSIST, $func);
if ($event->add()) {
$this->writeEvents[$fdKey] = $event;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Events/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,21 +381,21 @@ public function run(): void
foreach ($read as $fd) {
$fdKey = (int)$fd;
if (isset($this->readEvents[$fdKey])) {
$this->safeCall($this->readEvents[$fdKey], [$fd]);
$this->readEvents[$fdKey]($fd);
}
}

foreach ($write as $fd) {
$fdKey = (int)$fd;
if (isset($this->writeEvents[$fdKey])) {
$this->safeCall($this->writeEvents[$fdKey], [$fd]);
$this->writeEvents[$fdKey]($fd);
}
}

foreach ($except as $fd) {
$fdKey = (int)$fd;
if (isset($this->exceptEvents[$fdKey])) {
$this->safeCall($this->exceptEvents[$fdKey], [$fd]);
$this->exceptEvents[$fdKey]($fd);
}
}

Expand Down

0 comments on commit 1d25e3f

Please sign in to comment.