18
18
19
19
use function array_key_exists ;
20
20
use function array_pop ;
21
- use function assert ;
22
21
use function count ;
23
- use function is_int ;
24
22
use function Safe \hrtime ;
25
23
use function spl_object_id ;
26
24
@@ -108,8 +106,8 @@ public function close(): bool
108
106
109
107
$ this ->closed = TRUE_ ;
110
108
111
- foreach ($ this ->runtimes as $ hash => $ runtime ) {
112
- $ this ->closeRuntime ($ hash );
109
+ foreach ($ this ->runtimes as $ id => $ runtime ) {
110
+ $ this ->closeRuntime ($ id );
113
111
}
114
112
115
113
return TRUE_ ;
@@ -157,21 +155,20 @@ public function releaseGroup(GroupInterface $group): void
157
155
158
156
private function getIdleRuntime (): Runtime
159
157
{
160
- $ hash = array_pop ($ this ->idleRuntimes );
161
- assert (is_int ($ hash ));
158
+ $ id = array_pop ($ this ->idleRuntimes );
162
159
163
- if (array_key_exists ($ hash , $ this ->ttlTimers )) {
164
- Loop::cancelTimer ($ this ->ttlTimers [$ hash ]);
165
- unset($ this ->ttlTimers [$ hash ]);
160
+ if (array_key_exists ($ id , $ this ->ttlTimers )) {
161
+ Loop::cancelTimer ($ this ->ttlTimers [$ id ]);
162
+ unset($ this ->ttlTimers [$ id ]);
166
163
}
167
164
168
- return $ this ->runtimes [$ hash ];
165
+ return $ this ->runtimes [$ id ];
169
166
}
170
167
171
168
private function addRuntimeToIdleList (Runtime $ runtime ): void
172
169
{
173
- $ hash = spl_object_id ($ runtime );
174
- $ this ->idleRuntimes [$ hash ] = $ hash ;
170
+ $ id = spl_object_id ($ runtime );
171
+ $ this ->idleRuntimes [$ id ] = $ id ;
175
172
}
176
173
177
174
private function spawnRuntime (): Runtime
@@ -188,38 +185,43 @@ private function spawnRuntime(): Runtime
188
185
189
186
private function startTtlTimer (Runtime $ runtime ): void
190
187
{
191
- $ hash = spl_object_id ($ runtime );
188
+ $ id = spl_object_id ($ runtime );
192
189
193
- $ this ->ttlTimers [$ hash ] = Loop::addTimer ($ this ->ttl , function () use ($ hash ): void {
194
- $ this ->closeRuntime ($ hash );
190
+ $ this ->ttlTimers [$ id ] = Loop::addTimer ($ this ->ttl , function () use ($ id ): void {
191
+ $ this ->closeRuntime ($ id );
195
192
});
196
193
}
197
194
198
- private function closeRuntime (int $ hash ): void
195
+ private function closeRuntime (int $ id ): void
199
196
{
200
- $ runtime = $ this ->runtimes [$ hash ];
197
+ if (! array_key_exists ($ id , $ this ->runtimes )) {
198
+ return ;
199
+ }
200
+
201
+ // check if it exists
202
+ $ runtime = $ this ->runtimes [$ id ];
201
203
try {
202
204
$ runtime ->close ();
203
205
} catch (Closed ) {
204
206
// @ignoreException
205
207
}
206
208
207
- unset($ this ->runtimes [$ hash ]);
209
+ unset($ this ->runtimes [$ id ]);
208
210
209
- if (array_key_exists ($ hash , $ this ->idleRuntimes )) {
210
- unset($ this ->idleRuntimes [$ hash ]);
211
+ if (array_key_exists ($ id , $ this ->idleRuntimes )) {
212
+ unset($ this ->idleRuntimes [$ id ]);
211
213
}
212
214
213
215
if ($ this ->metrics instanceof Metrics) {
214
216
$ this ->metrics ->threads ()->gauge (new Label ('state ' , 'idle ' ))->dcr ();
215
217
}
216
218
217
- if (! array_key_exists ($ hash , $ this ->ttlTimers )) {
219
+ if (! array_key_exists ($ id , $ this ->ttlTimers )) {
218
220
return ;
219
221
}
220
222
221
- Loop::cancelTimer ($ this ->ttlTimers [$ hash ]);
223
+ Loop::cancelTimer ($ this ->ttlTimers [$ id ]);
222
224
223
- unset($ this ->ttlTimers [$ hash ]);
225
+ unset($ this ->ttlTimers [$ id ]);
224
226
}
225
227
}
0 commit comments