@@ -141,7 +141,7 @@ public function queue(\Closure $closure, mixed ...$args): void
141141
142142 public function defer (\Closure $ closure ): string
143143 {
144- $ deferCallback = new DeferCallback ($ this ->nextId ++ , $ closure );
144+ $ deferCallback = new DeferCallback ($ this ->callbackId () , $ closure );
145145
146146 $ this ->callbacks [$ deferCallback ->id ] = $ deferCallback ;
147147 $ this ->enableDeferQueue [$ deferCallback ->id ] = $ deferCallback ;
@@ -155,7 +155,7 @@ public function delay(float $delay, \Closure $closure): string
155155 throw new \Error ("Delay must be greater than or equal to zero " );
156156 }
157157
158- $ timerCallback = new TimerCallback ($ this ->nextId ++ , $ delay , $ closure , $ this ->now () + $ delay );
158+ $ timerCallback = new TimerCallback ($ this ->callbackId () , $ delay , $ closure , $ this ->now () + $ delay );
159159
160160 $ this ->callbacks [$ timerCallback ->id ] = $ timerCallback ;
161161 $ this ->enableQueue [$ timerCallback ->id ] = $ timerCallback ;
@@ -169,7 +169,7 @@ public function repeat(float $interval, \Closure $closure): string
169169 throw new \Error ("Interval must be greater than or equal to zero " );
170170 }
171171
172- $ timerCallback = new TimerCallback ($ this ->nextId ++ , $ interval , $ closure , $ this ->now () + $ interval , true );
172+ $ timerCallback = new TimerCallback ($ this ->callbackId () , $ interval , $ closure , $ this ->now () + $ interval , true );
173173
174174 $ this ->callbacks [$ timerCallback ->id ] = $ timerCallback ;
175175 $ this ->enableQueue [$ timerCallback ->id ] = $ timerCallback ;
@@ -179,7 +179,7 @@ public function repeat(float $interval, \Closure $closure): string
179179
180180 public function onReadable (mixed $ stream , \Closure $ closure ): string
181181 {
182- $ streamCallback = new StreamReadableCallback ($ this ->nextId ++ , $ closure , $ stream );
182+ $ streamCallback = new StreamReadableCallback ($ this ->callbackId () , $ closure , $ stream );
183183
184184 $ this ->callbacks [$ streamCallback ->id ] = $ streamCallback ;
185185 $ this ->enableQueue [$ streamCallback ->id ] = $ streamCallback ;
@@ -189,7 +189,7 @@ public function onReadable(mixed $stream, \Closure $closure): string
189189
190190 public function onWritable ($ stream , \Closure $ closure ): string
191191 {
192- $ streamCallback = new StreamWritableCallback ($ this ->nextId ++ , $ closure , $ stream );
192+ $ streamCallback = new StreamWritableCallback ($ this ->callbackId () , $ closure , $ stream );
193193
194194 $ this ->callbacks [$ streamCallback ->id ] = $ streamCallback ;
195195 $ this ->enableQueue [$ streamCallback ->id ] = $ streamCallback ;
@@ -199,7 +199,7 @@ public function onWritable($stream, \Closure $closure): string
199199
200200 public function onSignal (int $ signal , \Closure $ closure ): string
201201 {
202- $ signalCallback = new SignalCallback ($ this ->nextId ++ , $ closure , $ signal );
202+ $ signalCallback = new SignalCallback ($ this ->callbackId () , $ closure , $ signal );
203203
204204 $ this ->callbacks [$ signalCallback ->id ] = $ signalCallback ;
205205 $ this ->enableQueue [$ signalCallback ->id ] = $ signalCallback ;
@@ -640,6 +640,20 @@ private function createErrorCallback(): void
640640 };
641641 }
642642
643+ private function callbackId (): string
644+ {
645+ $ callbackId = $ this ->nextId ;
646+
647+ if (\PHP_VERSION_ID >= 80300 ) {
648+ /** @psalm-suppress UndefinedFunction */
649+ $ this ->nextId = \str_increment ($ this ->nextId );
650+ } else {
651+ $ this ->nextId ++;
652+ }
653+
654+ return $ callbackId ;
655+ }
656+
643657 final public function __serialize (): never
644658 {
645659 throw new \Error (__CLASS__ . ' does not support serialization ' );
0 commit comments