本文整理汇总了PHP中React\EventLoop\LoopInterface类的典型用法代码示例。如果您正苦于以下问题:PHP LoopInterface类的具体用法?PHP LoopInterface怎么用?PHP LoopInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LoopInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Create a new file driven handler instance.
*
* @param \Illuminate\Filesystem\Filesystem $files
* @param React\EventLoop\LoopInterface $loop
* @param string $path
*
* @return void
*/
public function __construct(Factory $factory, LoopInterface $loop, Server $server, $lifetime)
{
$this->factory = $factory;
$this->lifetime = $lifetime;
$this->server = $server;
$this->loop = $loop;
// PING redis connection every 5 minutes
// and try to reconnect on connection error
$this->timer = $loop->addPeriodicTimer(60 * 1, function () use($server) {
$this->promise->then(function ($client) use($server) {
$client->PING()->then(function ($pong) use($server) {
$server->log('Redis server responded ping with: %s', [$pong]);
return $pong == 'PONG';
}, function ($e) {
return $this->reconnectByError($e);
});
});
});
// server statistics for redis connection
$this->loop->addPeriodicTimer(60 * 30, function () {
$this->server->log('Server statistics to the last 30 minutes.');
$this->server->log('Best time of %fs, poor time of %fs and a average of %f seconds for total %d requests.', array_values($this->statistics));
$this->statistics = array('best' => 0, 'poor' => 0, 'avg' => 0, 'total' => 0);
});
}
示例2: __construct
public function __construct(TransportInterface $carrierProtocol, LoopInterface $loop, LoggerInterface $logger)
{
$that = $this;
$this->logger = $logger;
$this->loop = $loop;
$this->carrierProtocol = $carrierProtocol;
$this->actionEmitter = new EventEmitter();
$deferreds =& $this->deferred;
$timers =& $this->timers;
$carrierProtocol->on("message", function (MessageInterface $message) use(&$deferreds, &$timers, &$loop, $that, $logger) {
$string = $message->getData();
try {
$jsonMessage = RemoteEventMessage::fromJson($string);
$tag = $jsonMessage->getTag();
if (array_key_exists($tag, $deferreds)) {
$deferred = $deferreds[$tag];
unset($deferreds[$tag]);
if (array_key_exists($tag, $timers)) {
$loop->cancelTimer($timers[$tag]);
unset($timers[$tag]);
}
$deferred->resolve($jsonMessage);
} else {
$that->remoteEvent()->emit($jsonMessage->getEvent(), array($jsonMessage));
}
$that->emit("message", array($jsonMessage));
} catch (\Exception $e) {
$logger->err("Exception while parsing JsonMessage: " . $e->getMessage());
}
});
}
示例3: runDaemon
/**
* Starts downloader in daemon mode, awaiting for future tasks
* @todo Locks and signal processing
*
* @param EventLoop\LoopInterface $loop A loop, worker is run on
*/
public function runDaemon(EventLoop\LoopInterface $loop)
{
$loop->addPeriodicTimer($this->tick, function ($timer) use($loop) {
$this->run($loop, $this->limit);
});
$loop->run();
}
示例4:
function it_adds_a_read_stream($socket, ChannelInterface $channel, ConnectionInterface $connection, LoopInterface $loop)
{
$channel->getConnection()->willReturn($connection);
$connection->getSocket()->willReturn($socket);
$loop->addReadStream($socket, [$this, 'wait'])->shouldBeCalled();
$this->beConstructedWith($channel, $loop);
}
示例5: __construct
public function __construct(LoopInterface $loop, EventEmitter $emit, \SplObjectStorage $clients, RoundProcessor $roundProcessor, EngineHelper $helper, $time = 60, $debug = false)
{
$this->debug = $debug;
$this->helper = $helper;
$this->emit = $emit;
$this->loop = $loop;
$this->roundTimer = new RoundTimer($loop, $emit);
$this->roundNumber = 0;
$this->clients = $clients;
$this->disconnected = new \SplObjectStorage();
$this->time = $time;
$that = $this;
$this->say = new Say($this->clients);
$this->roundProcessor = $roundProcessor;
$players = new Say($this->clients);
// Setup listeners on the roundTimer object.
$emit->on('GAME.COUNTDOWN', function () use($that) {
if ($this->playerCount !== $this->clients->count()) {
$this->playerCount = $this->clients->count();
$this->say->to($this->clients)->that(Say::TICK, ["players" => $this->playerCount]);
}
});
// Setup listeners on the roundTimer object.
$emit->on('GAME.COUNTDOWN_END', function () use($that, $loop, $emit) {
$this->say->to($this->clients)->that(Say::GAME_STARTING, ["players" => $this->clients->count()]);
$this->setGameStarted(true);
$loop->addTimer(3, function () use($loop, $emit) {
$this->startRound($loop, $emit);
});
});
$this->roundTimer->startCountDown($this->time);
}
示例6: __construct
/**
* Create a new event pusher handler
*/
public function __construct(LoopInterface $loop, OutputInterface $output = null)
{
$this->loop = $loop;
$this->output = $output;
$this->clients = new \SplObjectStorage();
$this->subscriber = \Service::getContainer()->get('kernel.subscriber.bzion_subscriber');
// Ping timer
$loop->addPeriodicTimer(self::KEEP_ALIVE, array($this, 'ping'));
}
示例7: __construct
public function __construct(LoopInterface $loop)
{
$bspcProcess = proc_open('pactl subscribe', [['pipe', 'r'], ['pipe', 'w']], $pipes);
$bspcStdout = new Stream($pipes[1], $loop);
$bspcStdout->on('data', [$this, 'onUpdate']);
$loop->addTimer(0, function () {
$this->queryData();
});
}
示例8: __construct
public function __construct(LoopInterface $loop, FrameBuffer $frameBuffer, ContainerInterface $container)
{
$this->loop = $loop;
$this->frameBuffer = $frameBuffer;
$this->container = $container;
$this->connections = new \SplObjectStorage();
$fps = (double) $container->get('server.fps');
$this->update_timer = $this->loop->addPeriodicTimer(1.0 / $fps, [$this, 'onFrameUpdate']);
$this->switchToGameLoop($container->get(TestImageScreen::class));
}
示例9: __construct
/**
* NewEventLoopScheduler constructor.
* @param callable|LoopInterface $timerCallableOrLoop
*/
public function __construct($timerCallableOrLoop)
{
// passing a loop directly into the scheduler will be deprecated in the next major release
$this->timerCallable = $timerCallableOrLoop instanceof LoopInterface ? function ($ms, $callable) use($timerCallableOrLoop) {
$timerCallableOrLoop->addTimer($ms / 1000, $callable);
} : $timerCallableOrLoop;
parent::__construct($this->now(), function ($a, $b) {
return $a - $b;
});
}
示例10: start
/**
* Start the HTTP Server
*/
public function start()
{
$this->httpServer->on('request', [$this, 'handleRequest']);
$this->logger->info("Server is listening at " . $this->configuration['listen']['host'] . ":" . $this->configuration['listen']['port']);
$this->socketServer->listen($this->configuration['listen']['port'], $this->configuration['listen']['host']);
$this->eventLoop->run();
}
示例11: start
/**
* Adds timer to Loop queue
*
* @param float $interval
* @return TimerInterface
*/
public function start($interval = self::DEFAULT_INTERVAL)
{
if ($this->timer) {
$this->stop();
}
return $this->timer = $this->loop->addPeriodicTimer($interval, $this);
}
示例12: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->client->getUsers()->then(function ($users) use($output) {
$this->importUsers($users, $output);
});
$this->loop->run();
}
示例13: write
/**
* Listen for exit command and terminate
* the event loop
*
* @param string $data
* @return void
*/
public function write($data)
{
if (trim($data) === self::EXIT_CMD) {
$this->loop->stop();
$this->close();
}
}
示例14: getStatus
public function getStatus(callable $callback)
{
$this->request('status', [], function ($result) use($callback) {
$callback(json_decode($result, true));
});
$this->loop->run();
}
示例15: close
/**
*
*/
public function close()
{
$this->loop->removeReadStream($this->socket);
if (is_resource($this->socket)) {
fclose($this->socket);
}
$this->notifyCompleted();
}