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