WorkerExitCallback.php 896 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Framework\Bootstrap;
  12. use Hyperf\Coordinator\Constants;
  13. use Hyperf\Coordinator\CoordinatorManager;
  14. use Hyperf\Coroutine\Coroutine;
  15. use Hyperf\Framework\Event\OnWorkerExit;
  16. use Psr\EventDispatcher\EventDispatcherInterface;
  17. use Swoole\Server;
  18. class WorkerExitCallback
  19. {
  20. public function __construct(protected EventDispatcherInterface $dispatcher)
  21. {
  22. }
  23. public function onWorkerExit(Server $server, int $workerId)
  24. {
  25. $this->dispatcher->dispatch(new OnWorkerExit($server, $workerId));
  26. Coroutine::create(function () {
  27. CoordinatorManager::until(Constants::WORKER_EXIT)->resume();
  28. });
  29. }
  30. }