ProcessCollector.php 940 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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\Process;
  12. use Swoole\Process;
  13. /**
  14. * Only collect coroutine process.
  15. */
  16. class ProcessCollector
  17. {
  18. protected static array $processes = [];
  19. public static function add($name, Process $process)
  20. {
  21. static::$processes[$name][] = $process;
  22. }
  23. public static function get($name): array
  24. {
  25. return static::$processes[$name] ?? [];
  26. }
  27. public static function all(): array
  28. {
  29. $result = [];
  30. foreach (static::$processes as $processes) {
  31. $result = array_merge($result, $processes);
  32. }
  33. return $result;
  34. }
  35. public static function isEmpty(): bool
  36. {
  37. return static::$processes === [];
  38. }
  39. }