@@ -13,7 +13,15 @@ class EventQueue implements InterfaceEventQueue
1313 private const TIME_OUT = 10 ;
1414
1515 private static int $ nextId = 0 ;
16+
17+ /**
18+ * @var Queue[]
19+ */
1620 private static array $ queues = [];
21+
22+ /**
23+ * @var Queue[]
24+ */
1725 private static array $ returns = [];
1826
1927 private static function generateId () : int
@@ -54,7 +62,7 @@ public static function getQueue(int $id) : ?Queue
5462 return self ::$ queues [$ id ] ?? null ;
5563 }
5664
57- public static function getReturn (int $ id ) : mixed
65+ public static function getReturn (int $ id ) : ? Queue
5866 {
5967 return self ::$ returns [$ id ] ?? null ;
6068 }
@@ -98,7 +106,7 @@ private static function doResult(int $id) : void
98106 break ;
99107 case StatusQueue::PENDING :
100108 throw new EventQueueError (
101- str_replace ("%id% " , $ id , Error::QUEUE_STILL_PENDING )
109+ str_replace ("%id% " , " $ id" , Error::QUEUE_STILL_PENDING )
102110 );
103111 }
104112
@@ -108,7 +116,7 @@ private static function doResult(int $id) : void
108116 else
109117 {
110118 throw new EventQueueError (
111- str_replace ("%id% " , $ id , Error::QUEUE_NOT_FOUND )
119+ str_replace ("%id% " , " $ id" , Error::QUEUE_NOT_FOUND )
112120 );
113121 }
114122 }
@@ -136,20 +144,6 @@ public static function runQueue(int $id) : void
136144 }
137145 }
138146
139- /**
140- * @throws Throwable
141- */
142- private static function queueFulfilled (int $ id ) : bool
143- {
144- $ queue = self ::getQueue ($ id );
145- if ($ queue !== null )
146- {
147- $ status = $ queue ->getStatus ();
148- return $ status === StatusQueue::FULFILLED || $ status === StatusQueue::REJECTED ;
149- }
150- return false ;
151- }
152-
153147 /**
154148 * @throws Throwable
155149 */
@@ -275,7 +269,7 @@ private static function checkStatus(int $id) : void
275269 else
276270 {
277271 throw new EventQueueError (
278- str_replace ("%id% " , $ id , Error::QUEUE_NOT_FOUND )
272+ str_replace ("%id% " , " $ id" , Error::QUEUE_NOT_FOUND )
279273 );
280274 }
281275 }
@@ -298,24 +292,21 @@ private static function run() : void
298292 {
299293 foreach (self ::$ queues as $ id => $ queue )
300294 {
301- if ($ queue instanceof Queue )
295+ if (self :: shouldCheckStatus ( $ queue) )
302296 {
303-
304- if (self ::shouldCheckStatus ($ queue ))
305- {
306- self ::checkStatus ($ id );
307- }
297+ self ::checkStatus ($ id );
298+ }
308299
309- // If the queue is still pending after 10 seconds of timeout, reject it.
310- // If you encounter this problem, your current promise trick is too bad.
311- if (self ::shouldCheckStatus ($ queue , self ::TIME_OUT ))
312- {
313- self ::rejectQueue (
314- $ id , str_replace ("%id% " , $ id , Error::QUEUE_IS_TIMEOUT )
315- );
316- }
300+ // If the queue is still pending after 10 seconds of timeout, reject it.
301+ // If you encounter this problem, your current promise trick is too bad.
302+ if (self ::shouldCheckStatus ($ queue , self ::TIME_OUT ))
303+ {
304+ self ::rejectQueue (
305+ $ id , str_replace ("%id% " , "$ id " , Error::QUEUE_IS_TIMEOUT )
306+ );
317307 }
318308 }
309+
319310 foreach (self ::$ returns as $ id => $ queue )
320311 {
321312 $ canDrop = $ queue ->canDrop ();
0 commit comments