Coordinator.php 485 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace think\swoole;
  3. use Swoole\Coroutine\Channel;
  4. class Coordinator
  5. {
  6. /**
  7. * @var Channel
  8. */
  9. private $channel;
  10. public function __construct()
  11. {
  12. $this->channel = new Channel(1);
  13. }
  14. public function yield($timeout = -1): bool
  15. {
  16. $this->channel->pop((float) $timeout);
  17. return $this->channel->errCode === SWOOLE_CHANNEL_CLOSED;
  18. }
  19. public function resume(): void
  20. {
  21. $this->channel->close();
  22. }
  23. }