@@ -173,7 +173,7 @@ public function handle(Event $event) : void
173173 $ expecting = $ matcher ->nextAcceptedEvents ();
174174 $ result = $ matcher ->handle ($ event );
175175 if ($ this ->isFlagSet ($ result , $ matcher ::EVENT_HANDLED )) {
176- $ handledMatchers [] = $ matcher ;
176+ $ handledMatchers [spl_object_id ( $ matcher ) ] = $ matcher ;
177177 $ skipMatchers [] = get_class ($ matcher );
178178 /** Update which events we are expecting next **/
179179 $ this ->removeWatchForEvents ($ matcher , $ expecting );
@@ -186,7 +186,7 @@ public function handle(Event $event) : void
186186
187187 // If we are timed out then flag the matcher for timeout processing.
188188 if ($ this ->isFlagSet ($ result , $ matcher ::EVENT_TIMEOUT )) {
189- $ timedOutMatchers [] = $ matcher ;
189+ $ timedOutMatchers [spl_object_id ( $ matcher ) ] = $ matcher ;
190190 }
191191
192192 //Matcher has told us to suppress further processing of this event.
@@ -214,7 +214,7 @@ public function handle(Event $event) : void
214214 $ matcher = $ this ->constructMatcher ($ class );
215215 $ result = $ matcher ->handle ($ event );
216216 if ($ this ->isFlagSet ($ result , $ matcher ::EVENT_HANDLED )) {
217- $ handledMatchers [] = $ matcher ;
217+ $ handledMatchers [spl_object_id ( $ matcher ) ] = $ matcher ;
218218 $ this ->eventProcessors [spl_object_id ($ matcher )] = $ matcher ;
219219 $ this ->incrStat ('init_matcher ' , $ class );
220220 $ this ->incrStat ('handled ' , (string )$ event ->event . "| " . get_class ($ matcher ));
@@ -241,8 +241,21 @@ public function handle(Event $event) : void
241241 $ this ->incrStat ('unhandled ' , (string )$ event ->event );
242242 }
243243
244- /** For any matchers that processed this event fire any actions, then update timeout or destroy if complete **/
245244 $ stateChanged = !(empty ($ handledMatchers ) && empty ($ timedOutMatchers ));
245+
246+ /** Fire any action and destroy any timed out matchers **/
247+ foreach ($ timedOutMatchers as $ objectId => $ matcher ) {
248+ $ this ->removeTimeout ($ matcher );
249+ $ matcher ->fire ();
250+ /** Record stat of matcher timeout */
251+ $ this ->incrStat ('completed_matcher_timeout ' , get_class ($ matcher ));
252+ $ this ->removeMatcher ($ matcher );
253+ unset($ handledMatchers [$ objectId ]);
254+ unset($ matcher );
255+ }
256+ unset($ timedOutMatchers );
257+
258+ /** For any matchers that processed this event fire any actions, then update timeout or destroy if complete **/
246259 foreach ($ handledMatchers as $ matcher ) {
247260 $ matcher ->fire ();
248261 $ this ->addTimeout ($ matcher );
@@ -254,16 +267,7 @@ public function handle(Event $event) : void
254267 unset($ matcher );
255268 }
256269 }
257-
258- /** Fire any action and destroy any timed out matchers **/
259- foreach ($ timedOutMatchers as $ matcher ) {
260- $ this ->removeTimeout ($ matcher );
261- $ matcher ->fire ();
262- /** Record stat of matcher timeout */
263- $ this ->incrStat ('completed_matcher_timeout ' , get_class ($ matcher ));
264- $ this ->removeMatcher ($ matcher );
265- unset($ matcher );
266- }
270+ unset($ handledMatchers );
267271
268272 /** Flag as dirty except when we have a control message and state doesn't change **/
269273 if ($ stateChanged || !in_array ($ event ->event , Scheduler::CONTROL_MESSAGES , true )) {
0 commit comments