ChannelInterface.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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\Engine\Contract;
  12. /**
  13. * @template TValue of mixed
  14. */
  15. interface ChannelInterface
  16. {
  17. /**
  18. * @param TValue $data
  19. * @param float|int $timeout seconds [optional] = -1
  20. */
  21. public function push(mixed $data, float $timeout = -1): bool;
  22. /**
  23. * @param float $timeout seconds [optional] = -1
  24. * @return false|TValue when pop failed, return false
  25. */
  26. public function pop(float $timeout = -1): mixed;
  27. /**
  28. * Swow: When the channel is closed, all the data in it will be destroyed.
  29. * Swoole: When the channel is closed, the data in it can still be popped out, but push behavior will no longer succeed.
  30. */
  31. public function close(): bool;
  32. public function getCapacity(): int;
  33. public function getLength(): int;
  34. public function isAvailable(): bool;
  35. public function hasProducers(): bool;
  36. public function hasConsumers(): bool;
  37. public function isEmpty(): bool;
  38. public function isFull(): bool;
  39. public function isReadable(): bool;
  40. public function isWritable(): bool;
  41. public function isClosing(): bool;
  42. public function isTimeout(): bool;
  43. }