Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions src/EventLoop/Internal/AbstractDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@

public function defer(\Closure $closure): string
{
$deferCallback = new DeferCallback($this->nextId++, $closure);
$deferCallback = new DeferCallback($this->callbackId(), $closure);

$this->callbacks[$deferCallback->id] = $deferCallback;
$this->enableDeferQueue[$deferCallback->id] = $deferCallback;
Expand All @@ -155,7 +155,7 @@
throw new \Error("Delay must be greater than or equal to zero");
}

$timerCallback = new TimerCallback($this->nextId++, $delay, $closure, $this->now() + $delay);
$timerCallback = new TimerCallback($this->callbackId(), $delay, $closure, $this->now() + $delay);

$this->callbacks[$timerCallback->id] = $timerCallback;
$this->enableQueue[$timerCallback->id] = $timerCallback;
Expand All @@ -169,7 +169,7 @@
throw new \Error("Interval must be greater than or equal to zero");
}

$timerCallback = new TimerCallback($this->nextId++, $interval, $closure, $this->now() + $interval, true);
$timerCallback = new TimerCallback($this->callbackId(), $interval, $closure, $this->now() + $interval, true);

$this->callbacks[$timerCallback->id] = $timerCallback;
$this->enableQueue[$timerCallback->id] = $timerCallback;
Expand All @@ -179,7 +179,7 @@

public function onReadable(mixed $stream, \Closure $closure): string
{
$streamCallback = new StreamReadableCallback($this->nextId++, $closure, $stream);
$streamCallback = new StreamReadableCallback($this->callbackId(), $closure, $stream);

$this->callbacks[$streamCallback->id] = $streamCallback;
$this->enableQueue[$streamCallback->id] = $streamCallback;
Expand All @@ -189,7 +189,7 @@

public function onWritable($stream, \Closure $closure): string
{
$streamCallback = new StreamWritableCallback($this->nextId++, $closure, $stream);
$streamCallback = new StreamWritableCallback($this->callbackId(), $closure, $stream);

$this->callbacks[$streamCallback->id] = $streamCallback;
$this->enableQueue[$streamCallback->id] = $streamCallback;
Expand All @@ -199,7 +199,7 @@

public function onSignal(int $signal, \Closure $closure): string
{
$signalCallback = new SignalCallback($this->nextId++, $closure, $signal);
$signalCallback = new SignalCallback($this->callbackId(), $closure, $signal);

$this->callbacks[$signalCallback->id] = $signalCallback;
$this->enableQueue[$signalCallback->id] = $signalCallback;
Expand Down Expand Up @@ -640,6 +640,19 @@
};
}

private function callbackId(): string
{
$callbackId = $this->nextId;

if (\PHP_VERSION_ID >= 80300) {
$this->nextId = str_increment($this->nextId);

Check failure on line 648 in src/EventLoop/Internal/AbstractDriver.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

UndefinedFunction

src/EventLoop/Internal/AbstractDriver.php:648:29: UndefinedFunction: Function Revolt\EventLoop\Internal\str_increment does not exist (see https://psalm.dev/021)

Check failure on line 648 in src/EventLoop/Internal/AbstractDriver.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

UndefinedFunction

src/EventLoop/Internal/AbstractDriver.php:648:29: UndefinedFunction: Function Revolt\EventLoop\Internal\str_increment does not exist (see https://psalm.dev/021)
} else {
$this->nextId++;
}

return $callbackId;
}

final public function __serialize(): never
{
throw new \Error(__CLASS__ . ' does not support serialization');
Expand Down
Loading