From 8d1b77238218a3bd5dcec4c2fb5ef935c1c57431 Mon Sep 17 00:00:00 2001 From: Joop Schilder Date: Wed, 16 Jan 2019 16:53:44 +0100 Subject: [PATCH] Added await all --- src/Asynchronous.php | 17 +++++++++++++---- src/functions.php | 11 +++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Asynchronous.php b/src/Asynchronous.php index 7f0d3ec..e46efbf 100644 --- a/src/Asynchronous.php +++ b/src/Asynchronous.php @@ -97,6 +97,18 @@ class Asynchronous } } + /** + * + */ + public static function awaitChildren() + { + $instance = self::getInstance(); + while (count($instance->children) > 0) { + pcntl_wait($status); + array_shift($instance->children); + } + } + /** * @return int */ @@ -199,10 +211,7 @@ class Asynchronous * ensure that all writing to the shared * memory block is finished. */ - while (count($instance->children) > 0) { - pcntl_wait($status); - array_shift($instance->children); - } + self::awaitChildren(); /* * Ask the kernel to mark the shared memory diff --git a/src/functions.php b/src/functions.php index ab65b50..a79405b 100644 --- a/src/functions.php +++ b/src/functions.php @@ -25,3 +25,14 @@ if (!function_exists('async_cleanup')) { Asynchronous::cleanup(); } } + + +if (!function_exists('async_await_all')) { + /** + * + */ + function async_await_all() + { + Asynchronous::awaitChildren(); + } +} \ No newline at end of file