ChannelInterface.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. if (PHP_VERSION_ID > 80000 && SWOOLE_VERSION_ID >= 50000) {
  13. interface ChannelInterface
  14. {
  15. /**
  16. * @param float|int $timeout [optional] = -1
  17. */
  18. public function push(mixed $data, float $timeout = -1): bool;
  19. /**
  20. * @param float $timeout seconds [optional] = -1
  21. * @return mixed when pop failed, return false
  22. */
  23. public function pop(float $timeout = -1): mixed;
  24. /**
  25. * Swow: When the channel is closed, all the data in it will be destroyed.
  26. * Swoole: When the channel is closed, the data in it can still be popped out, but push behavior will no longer succeed.
  27. */
  28. public function close(): bool;
  29. public function getCapacity(): int;
  30. public function getLength(): int;
  31. public function isAvailable(): bool;
  32. public function hasProducers(): bool;
  33. public function hasConsumers(): bool;
  34. public function isEmpty(): bool;
  35. public function isFull(): bool;
  36. public function isReadable(): bool;
  37. public function isWritable(): bool;
  38. public function isClosing(): bool;
  39. public function isTimeout(): bool;
  40. }
  41. } else {
  42. interface ChannelInterface
  43. {
  44. /**
  45. * @param mixed $data [required]
  46. * @param float|int $timeout [optional] = -1
  47. * @return bool
  48. */
  49. public function push($data, $timeout = -1);
  50. /**
  51. * @param float $timeout seconds [optional] = -1
  52. * @return mixed when pop failed, return false
  53. */
  54. public function pop($timeout = -1);
  55. /**
  56. * Swow: When the channel is closed, all the data in it will be destroyed.
  57. * Swoole: When the channel is closed, the data in it can still be popped out, but push behavior will no longer succeed.
  58. * @return mixed
  59. */
  60. public function close(): bool;
  61. /**
  62. * @return int
  63. */
  64. public function getCapacity();
  65. /**
  66. * @return int
  67. */
  68. public function getLength();
  69. /**
  70. * @return bool
  71. */
  72. public function isAvailable();
  73. /**
  74. * @return bool
  75. */
  76. public function hasProducers();
  77. /**
  78. * @return bool
  79. */
  80. public function hasConsumers();
  81. /**
  82. * @return bool
  83. */
  84. public function isEmpty();
  85. /**
  86. * @return bool
  87. */
  88. public function isFull();
  89. /**
  90. * @return bool
  91. */
  92. public function isReadable();
  93. /**
  94. * @return bool
  95. */
  96. public function isWritable();
  97. /**
  98. * @return bool
  99. */
  100. public function isClosing();
  101. /**
  102. * @return bool
  103. */
  104. public function isTimeout();
  105. }
  106. }