From 4531e594a2a93c302ba81b40205477fa0dde6d7d Mon Sep 17 00:00:00 2001 From: Netkas Date: Fri, 30 Jun 2023 00:58:08 -0400 Subject: [PATCH] `\TamerLib > tm > do()` the parameter `$callback` is now optional. If not provided, the job result will not be handled by the client and just be discarded. --- CHANGELOG.md | 4 ++++ src/TamerLib/tm.php | 13 +++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8df39e..31a41bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ Minor bugfixes and improvements. ### Fixed - Fixed bug where `\TamerLib > tm > run()` would return early even if the `$timeout` is set to 0. +### Changed + - `\TamerLib > tm > do()` the parameter `$callback` is now optional. If not provided, the job result will not be + handled by the client and just be discarded. + ## [2.0.0] - 2023-06-18 This version of TamerLib offers a comprehensive framework for implementing parallel processing in PHP applications. diff --git a/src/TamerLib/tm.php b/src/TamerLib/tm.php index 8922062..b311fd8 100644 --- a/src/TamerLib/tm.php +++ b/src/TamerLib/tm.php @@ -420,18 +420,17 @@ * Waits for all the dispatched jobs to complete, this is a blocking function and will not return until all the * jobs have completed. If a timeout is specified, the function will return after the timeout has been reached. * - * @param callable $callback A callback function that will be called after each iteration of the wait loop + * @param callable|null $callback A callback function that will be called after each iteration of the wait loop * @param int $timeout The timeout in seconds, if 0 is provided then the function will block until all the jobs * have completed, if -1 is provided then the function run for one iteration and return * @return void + * @throws ConnectionException If the client fails to connect to the server * @throws JobManagerException If the JobManager throws an exception * @throws TamerException If the Tamer throws an exception - * @throws TimeoutException If the timeout is reached - * @throws ConnectionException If the client fails to connect to the server - * @throws Exception If a job fails * @throws Throwable If a job fails + * @throws TimeoutException If the timeout is reached */ - public static function wait(callable $callback, int $timeout=0): void + public static function wait(?callable $callback=null, int $timeout=0): void { if(self::$mode !== TamerMode::CLIENT) { @@ -460,15 +459,13 @@ self::removeFromWatchlist($job_packet->getId()); self::$job_manager->dropJob($job_packet->getId()); - if($job_packet->getStatus() === JobStatus::FINISHED) + if($callback !== null && $job_packet->getStatus() === JobStatus::FINISHED) { $return_value = $job_packet->getReturnValue(); - if($return_value !== null) { $return_value = unserialize($return_value, ['allowed_classes' => true]); } - $callback($job_packet->getId(), $return_value); } elseif($job_packet->getStatus() === JobStatus::FAILED)