Skip to content

Commit 9637fed

Browse files
authored
Merge pull request #56 from CharlotteDunoisLabs/patch-child-fd
Use native PHP indexing for child process file descriptors
2 parents 72ae332 + 508ec77 commit 9637fed

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/ChildProcess/Adapter.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,18 @@ public function mkdir($path, $mode = self::CREATION_MODE)
202202
*/
203203
public function open($path, $flags, $mode = self::CREATION_MODE)
204204
{
205-
$id = null;
206-
return \WyriHaximus\React\ChildProcess\Messenger\Factory::parentFromClass(self::CHILD_CLASS_NAME, $this->loop)->then(function (Messenger $messenger) use (&$id, $path, $flags, $mode) {
207-
$id = count($this->fileDescriptors);
208-
$this->fileDescriptors[$id] = $messenger;
205+
return \WyriHaximus\React\ChildProcess\Messenger\Factory::parentFromClass(self::CHILD_CLASS_NAME, $this->loop)->then(function (Messenger $messenger) use ($path, $flags, $mode) {
206+
$this->fileDescriptors[] = $messenger;
207+
\end($this->fileDescriptors);
208+
$id = \key($this->fileDescriptors);
209+
209210
return $this->fileDescriptors[$id]->rpc(Factory::rpc('open', [
210211
'path' => $path,
211212
'flags' => $flags,
212213
'mode' => $mode,
213-
]));
214-
})->then(function () use (&$id) {
215-
return $id;
214+
]))->then(function () use ($id) {
215+
return $id;
216+
});
216217
});
217218
}
218219

0 commit comments

Comments
 (0)