From 508ec7745c76d724877f9cbe8f77c3542f94802a Mon Sep 17 00:00:00 2001 From: Charlotte Dunois Date: Mon, 14 Jan 2019 18:08:13 +0100 Subject: [PATCH] Append to FD array and let PHP handle the indexing --- src/ChildProcess/Adapter.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/ChildProcess/Adapter.php b/src/ChildProcess/Adapter.php index 5aa118e3..76f67335 100644 --- a/src/ChildProcess/Adapter.php +++ b/src/ChildProcess/Adapter.php @@ -202,17 +202,18 @@ public function mkdir($path, $mode = self::CREATION_MODE) */ public function open($path, $flags, $mode = self::CREATION_MODE) { - $id = null; - return \WyriHaximus\React\ChildProcess\Messenger\Factory::parentFromClass(self::CHILD_CLASS_NAME, $this->loop)->then(function (Messenger $messenger) use (&$id, $path, $flags, $mode) { - $id = count($this->fileDescriptors); - $this->fileDescriptors[$id] = $messenger; + return \WyriHaximus\React\ChildProcess\Messenger\Factory::parentFromClass(self::CHILD_CLASS_NAME, $this->loop)->then(function (Messenger $messenger) use ($path, $flags, $mode) { + $this->fileDescriptors[] = $messenger; + \end($this->fileDescriptors); + $id = \key($this->fileDescriptors); + return $this->fileDescriptors[$id]->rpc(Factory::rpc('open', [ 'path' => $path, 'flags' => $flags, 'mode' => $mode, - ])); - })->then(function () use (&$id) { - return $id; + ]))->then(function () use ($id) { + return $id; + }); }); }