From b94a929806904079a2712582fad71d12aae9a3f4 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Thu, 31 Aug 2023 21:56:02 -0500 Subject: [PATCH] Return closed stream if STDIO stream is closed --- composer.json | 3 ++- src/Internal/functions.php | 33 +++++++++++++++++++++++++++++++++ src/functions.php | 6 +++--- 3 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 src/Internal/functions.php diff --git a/composer.json b/composer.json index 7323540..d7b8699 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,8 @@ "Amp\\ByteStream\\": "src" }, "files": [ - "src/functions.php" + "src/functions.php", + "src/Internal/functions.php" ] }, "autoload-dev": { diff --git a/src/Internal/functions.php b/src/Internal/functions.php new file mode 100644 index 0000000..a696185 --- /dev/null +++ b/src/Internal/functions.php @@ -0,0 +1,33 @@ +close(); + + return $stream; +} diff --git a/src/functions.php b/src/functions.php index f1ec0ba..311e23f 100644 --- a/src/functions.php +++ b/src/functions.php @@ -92,7 +92,7 @@ function getStdin(): ReadableResourceStream $map ??= new \WeakMap(); - return $map[EventLoop::getDriver()] ??= new ReadableResourceStream(\STDIN); + return $map[EventLoop::getDriver()] ??= Internal\tryToCreateReadableStreamFromResource(\STDIN); } /** @@ -104,7 +104,7 @@ function getStdout(): WritableResourceStream $map ??= new \WeakMap(); - return $map[EventLoop::getDriver()] ??= new WritableResourceStream(\STDOUT); + return $map[EventLoop::getDriver()] ??= Internal\tryToCreateWritableStreamFromResource(\STDOUT); } /** @@ -116,7 +116,7 @@ function getStderr(): WritableResourceStream $map ??= new \WeakMap(); - return $map[EventLoop::getDriver()] ??= new WritableResourceStream(\STDERR); + return $map[EventLoop::getDriver()] ??= Internal\tryToCreateWritableStreamFromResource(\STDERR); } /**