diff --git a/src/EventLoop/Internal/AbstractDriver.php b/src/EventLoop/Internal/AbstractDriver.php index 94de316..615c30e 100644 --- a/src/EventLoop/Internal/AbstractDriver.php +++ b/src/EventLoop/Internal/AbstractDriver.php @@ -141,7 +141,9 @@ public function queue(\Closure $closure, mixed ...$args): void public function defer(\Closure $closure): string { - $deferCallback = new DeferCallback($this->nextId++, $closure); + $id = $this->nextId; + \PHP_VERSION_ID >= 80300 ? $this->nextId = str_increment($this->nextId) : ++$this->nextId; + $deferCallback = new DeferCallback($id, $closure); $this->callbacks[$deferCallback->id] = $deferCallback; $this->enableDeferQueue[$deferCallback->id] = $deferCallback; @@ -155,7 +157,9 @@ public function delay(float $delay, \Closure $closure): string throw new \Error("Delay must be greater than or equal to zero"); } - $timerCallback = new TimerCallback($this->nextId++, $delay, $closure, $this->now() + $delay); + $id = $this->nextId; + \PHP_VERSION_ID >= 80300 ? $this->nextId = str_increment($this->nextId) : ++$this->nextId; + $timerCallback = new TimerCallback($id, $delay, $closure, $this->now() + $delay); $this->callbacks[$timerCallback->id] = $timerCallback; $this->enableQueue[$timerCallback->id] = $timerCallback; @@ -169,7 +173,9 @@ public function repeat(float $interval, \Closure $closure): string throw new \Error("Interval must be greater than or equal to zero"); } - $timerCallback = new TimerCallback($this->nextId++, $interval, $closure, $this->now() + $interval, true); + $id = $this->nextId; + \PHP_VERSION_ID >= 80300 ? $this->nextId = str_increment($this->nextId) : ++$this->nextId; + $timerCallback = new TimerCallback($id, $interval, $closure, $this->now() + $interval, true); $this->callbacks[$timerCallback->id] = $timerCallback; $this->enableQueue[$timerCallback->id] = $timerCallback; @@ -179,7 +185,9 @@ public function repeat(float $interval, \Closure $closure): string public function onReadable(mixed $stream, \Closure $closure): string { - $streamCallback = new StreamReadableCallback($this->nextId++, $closure, $stream); + $id = $this->nextId; + \PHP_VERSION_ID >= 80300 ? $this->nextId = str_increment($this->nextId) : ++$this->nextId; + $streamCallback = new StreamReadableCallback($id, $closure, $stream); $this->callbacks[$streamCallback->id] = $streamCallback; $this->enableQueue[$streamCallback->id] = $streamCallback; @@ -189,7 +197,9 @@ public function onReadable(mixed $stream, \Closure $closure): string public function onWritable($stream, \Closure $closure): string { - $streamCallback = new StreamWritableCallback($this->nextId++, $closure, $stream); + $id = $this->nextId; + \PHP_VERSION_ID >= 80300 ? $this->nextId = str_increment($this->nextId) : ++$this->nextId; + $streamCallback = new StreamWritableCallback($id, $closure, $stream); $this->callbacks[$streamCallback->id] = $streamCallback; $this->enableQueue[$streamCallback->id] = $streamCallback; @@ -199,7 +209,9 @@ public function onWritable($stream, \Closure $closure): string public function onSignal(int $signal, \Closure $closure): string { - $signalCallback = new SignalCallback($this->nextId++, $closure, $signal); + $id = $this->nextId; + \PHP_VERSION_ID >= 80300 ? $this->nextId = str_increment($this->nextId) : ++$this->nextId; + $signalCallback = new SignalCallback($id, $closure, $signal); $this->callbacks[$signalCallback->id] = $signalCallback; $this->enableQueue[$signalCallback->id] = $signalCallback;