\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.
This commit is contained in:
parent
a8b6f06b6d
commit
4531e594a2
2 changed files with 9 additions and 8 deletions
|
@ -12,6 +12,10 @@ Minor bugfixes and improvements.
|
||||||
### Fixed
|
### Fixed
|
||||||
- Fixed bug where `\TamerLib > tm > run()` would return early even if the `$timeout` is set to 0.
|
- 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
|
## [2.0.0] - 2023-06-18
|
||||||
|
|
||||||
This version of TamerLib offers a comprehensive framework for implementing parallel processing in PHP applications.
|
This version of TamerLib offers a comprehensive framework for implementing parallel processing in PHP applications.
|
||||||
|
|
|
@ -420,18 +420,17 @@
|
||||||
* Waits for all the dispatched jobs to complete, this is a blocking function and will not return until all the
|
* 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.
|
* 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
|
* @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
|
* have completed, if -1 is provided then the function run for one iteration and return
|
||||||
* @return void
|
* @return void
|
||||||
|
* @throws ConnectionException If the client fails to connect to the server
|
||||||
* @throws JobManagerException If the JobManager throws an exception
|
* @throws JobManagerException If the JobManager throws an exception
|
||||||
* @throws TamerException If the Tamer 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 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)
|
if(self::$mode !== TamerMode::CLIENT)
|
||||||
{
|
{
|
||||||
|
@ -460,15 +459,13 @@
|
||||||
self::removeFromWatchlist($job_packet->getId());
|
self::removeFromWatchlist($job_packet->getId());
|
||||||
self::$job_manager->dropJob($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();
|
$return_value = $job_packet->getReturnValue();
|
||||||
|
|
||||||
if($return_value !== null)
|
if($return_value !== null)
|
||||||
{
|
{
|
||||||
$return_value = unserialize($return_value, ['allowed_classes' => true]);
|
$return_value = unserialize($return_value, ['allowed_classes' => true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$callback($job_packet->getId(), $return_value);
|
$callback($job_packet->getId(), $return_value);
|
||||||
}
|
}
|
||||||
elseif($job_packet->getStatus() === JobStatus::FAILED)
|
elseif($job_packet->getStatus() === JobStatus::FAILED)
|
||||||
|
|
Loading…
Add table
Reference in a new issue