Skip to content

Commit 6826af3

Browse files
committed
Rename hash to id as it's actually a SPL object ID not the hash
1 parent 08b038c commit 6826af3

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

src/Infinite.php

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818

1919
use function array_key_exists;
2020
use function array_pop;
21-
use function assert;
2221
use function count;
23-
use function is_int;
2422
use function Safe\hrtime;
2523
use function spl_object_id;
2624

@@ -108,8 +106,8 @@ public function close(): bool
108106

109107
$this->closed = TRUE_;
110108

111-
foreach ($this->runtimes as $hash => $runtime) {
112-
$this->closeRuntime($hash);
109+
foreach ($this->runtimes as $id => $runtime) {
110+
$this->closeRuntime($id);
113111
}
114112

115113
return TRUE_;
@@ -157,21 +155,20 @@ public function releaseGroup(GroupInterface $group): void
157155

158156
private function getIdleRuntime(): Runtime
159157
{
160-
$hash = array_pop($this->idleRuntimes);
161-
assert(is_int($hash));
158+
$id = array_pop($this->idleRuntimes);
162159

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]);
166163
}
167164

168-
return $this->runtimes[$hash];
165+
return $this->runtimes[$id];
169166
}
170167

171168
private function addRuntimeToIdleList(Runtime $runtime): void
172169
{
173-
$hash = spl_object_id($runtime);
174-
$this->idleRuntimes[$hash] = $hash;
170+
$id = spl_object_id($runtime);
171+
$this->idleRuntimes[$id] = $id;
175172
}
176173

177174
private function spawnRuntime(): Runtime
@@ -188,38 +185,39 @@ private function spawnRuntime(): Runtime
188185

189186
private function startTtlTimer(Runtime $runtime): void
190187
{
191-
$hash = spl_object_id($runtime);
188+
$id = spl_object_id($runtime);
192189

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);
195192
});
196193
}
197194

198-
private function closeRuntime(int $hash): void
195+
private function closeRuntime(int $id): void
199196
{
200-
$runtime = $this->runtimes[$hash];
197+
// check if it exists
198+
$runtime = $this->runtimes[$id];
201199
try {
202200
$runtime->close();
203201
} catch (Closed) {
204202
// @ignoreException
205203
}
206204

207-
unset($this->runtimes[$hash]);
205+
unset($this->runtimes[$id]);
208206

209-
if (array_key_exists($hash, $this->idleRuntimes)) {
210-
unset($this->idleRuntimes[$hash]);
207+
if (array_key_exists($id, $this->idleRuntimes)) {
208+
unset($this->idleRuntimes[$id]);
211209
}
212210

213211
if ($this->metrics instanceof Metrics) {
214212
$this->metrics->threads()->gauge(new Label('state', 'idle'))->dcr();
215213
}
216214

217-
if (! array_key_exists($hash, $this->ttlTimers)) {
215+
if (! array_key_exists($id, $this->ttlTimers)) {
218216
return;
219217
}
220218

221-
Loop::cancelTimer($this->ttlTimers[$hash]);
219+
Loop::cancelTimer($this->ttlTimers[$id]);
222220

223-
unset($this->ttlTimers[$hash]);
221+
unset($this->ttlTimers[$id]);
224222
}
225223
}

0 commit comments

Comments
 (0)