Move waiter from Utils\Coroutine\Waiter to Utils src

This commit is contained in:
huangzhhui 2020-12-07 01:51:34 +08:00 committed by 李铭昕
parent c155ddfab9
commit 600817be72
7 changed files with 21 additions and 38 deletions

View File

@ -48,7 +48,7 @@
- [#2659](https://github.com/hyperf/hyperf/pull/2659) [#2663](https://github.com/hyperf/hyperf/pull/2663) Support `HttpServer` for [Swow](https://github.com/swow/swow).
- [#2671](https://github.com/hyperf/hyperf/pull/2671) Added `Hyperf\AsyncQueue\Listener\QueueHandleListener` which can record running logs for async-queue.
- [#2923](https://github.com/hyperf/hyperf/pull/2923) Added `Hyperf\Utils\Coroutine\Waiter\Waiter` which can wait coroutine to end.
- [#2923](https://github.com/hyperf/hyperf/pull/2923) Added `Hyperf\Utils\Waiter` which can wait coroutine to end.
## Fixed

View File

@ -1,26 +0,0 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Utils\Coroutine\Waiter;
use Closure;
use Hyperf\Utils\ApplicationContext;
if (! function_exists('Hyperf\\Utils\\Coroutine\\Waiter\\wait')) {
function wait(Closure $closure, ?float $timeout = null)
{
if (ApplicationContext::hasContainer()) {
$waiter = ApplicationContext::getContainer()->get(Waiter::class);
return $waiter->wait($closure, $timeout);
}
return (new Waiter())->wait($closure, $timeout);
}
}

View File

@ -9,7 +9,7 @@ declare(strict_types=1);
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Utils\Coroutine\Waiter;
namespace Hyperf\Utils\Exception;
use Throwable;

View File

@ -9,9 +9,7 @@ declare(strict_types=1);
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Utils\Coroutine\Waiter\Exception;
use Hyperf\Utils\Exception\TimeoutException;
namespace Hyperf\Utils\Exception;
class WaitTimeoutException extends TimeoutException
{

View File

@ -14,6 +14,7 @@ use Hyperf\Utils\Arr;
use Hyperf\Utils\Backoff;
use Hyperf\Utils\Collection;
use Hyperf\Utils\Coroutine;
use Hyperf\Utils\Waiter;
use Hyperf\Utils\HigherOrderTapProxy;
use Hyperf\Utils\Optional;
use Hyperf\Utils\Parallel;
@ -468,3 +469,14 @@ if (! function_exists('optional')) {
}
}
}
if (! function_exists('wait')) {
function wait(Closure $closure, ?float $timeout = null)
{
if (ApplicationContext::hasContainer()) {
$waiter = ApplicationContext::getContainer()->get(Waiter::class);
return $waiter->wait($closure, $timeout);
}
return (new Waiter())->wait($closure, $timeout);
}
}

View File

@ -9,12 +9,12 @@ declare(strict_types=1);
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Utils\Coroutine\Waiter;
namespace Hyperf\Utils;
use Closure;
use Hyperf\Engine\Channel;
use Hyperf\Utils\Coroutine;
use Hyperf\Utils\Coroutine\Waiter\Exception\WaitTimeoutException;
use Hyperf\Utils\Exception\ExceptionThrower;
use Hyperf\Utils\Exception\WaitTimeoutException;
use Throwable;
class Waiter

View File

@ -14,12 +14,11 @@ namespace HyperfTest\Utils\Waiter;
use Hyperf\Engine\Channel;
use Hyperf\Utils\ApplicationContext;
use Hyperf\Utils\Coroutine;
use Hyperf\Utils\Coroutine\Waiter\Exception\WaitTimeoutException;
use Hyperf\Utils\Coroutine\Waiter\Waiter;
use Hyperf\Utils\Exception\WaitTimeoutException;
use Mockery;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use function Hyperf\Utils\Coroutine\Waiter\wait;
use function wait;
/**
* @internal
@ -31,7 +30,7 @@ class WaiterTest extends TestCase
{
$container = Mockery::mock(ContainerInterface::class);
ApplicationContext::setContainer($container);
$container->shouldReceive('get')->with(Waiter::class)->andReturn(new Waiter());
$container->shouldReceive('get')->with(\Hyperf\Utils\Waiter::class)->andReturn(new \Hyperf\Utils\Waiter());
}
protected function tearDown(): void