You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
485 B
29 lines
485 B
<?php
|
|
|
|
namespace think\swoole;
|
|
|
|
use Swoole\Coroutine\Channel;
|
|
|
|
class Coordinator
|
|
{
|
|
/**
|
|
* @var Channel
|
|
*/
|
|
private $channel;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->channel = new Channel(1);
|
|
}
|
|
|
|
public function yield($timeout = -1): bool
|
|
{
|
|
$this->channel->pop((float) $timeout);
|
|
return $this->channel->errCode === SWOOLE_CHANNEL_CLOSED;
|
|
}
|
|
|
|
public function resume(): void
|
|
{
|
|
$this->channel->close();
|
|
}
|
|
}
|
|
|