File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -78,7 +78,6 @@ class EventLoop implements EventLoopInterface
7878 * @var array<int, Promise>
7979 */
8080 protected static array $ returns = [];
81- protected static bool $ isCleaningGarbage = false ;
8281
8382 public static function init (): void
8483 {
@@ -175,10 +174,15 @@ protected static function run(): void
175174 {
176175 if (count (GreenThread::getFibers ()) > 0 ) GreenThread::run ();
177176
177+ $ i = 0 ;
178+ $ limit = min ((int )((count (self ::$ queues ) / 2 ) + 1 ), 100 ); // Limit 100 promises per loop
179+
178180 /**
179181 * @var Promise $promise
180182 */
181183 foreach (self ::getQueues () as $ promise ) {
184+ if ($ i >= $ limit ) break ;
185+
182186 $ id = $ promise ->getId ();
183187 $ fiber = $ promise ->getFiber ();
184188
@@ -196,7 +200,12 @@ protected static function run(): void
196200 }
197201 MicroTask::addTask ($ id , $ promise );
198202 self ::$ queues ->offsetUnset ($ promise ); // Remove from queue
203+ } else {
204+ self ::$ queues ->detach ($ promise ); // Remove from queue
205+ self ::$ queues ->attach ($ promise , $ id ); // Add to queue again
199206 }
207+
208+ $ i ++;
200209 }
201210
202211 if (count (MicroTask::getTasks ()) > 0 ) MicroTask::run ();
@@ -213,4 +222,4 @@ protected static function runSingle(): void
213222 while (count (self ::$ queues ) > 0 || count (MicroTask::getTasks ()) > 0 || count (MacroTask::getTasks ()) > 0 || count (GreenThread::getFibers ()) > 0 ) self ::run ();
214223 }
215224
216- }
225+ }
You can’t perform that action at this time.
0 commit comments