本文整理汇总了PHP中React\EventLoop\LoopInterface::cancelTimer方法的典型用法代码示例。如果您正苦于以下问题:PHP LoopInterface::cancelTimer方法的具体用法?PHP LoopInterface::cancelTimer怎么用?PHP LoopInterface::cancelTimer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类React\EventLoop\LoopInterface
的用法示例。
在下文中一共展示了LoopInterface::cancelTimer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
$this->deferred = new Deferred();
$this->deferred->promise()->progress(function ($event) {
$this->data[$event['part']] = $event['data'];
unset($this->unsettled[$event['part']]);
if ($this->isEverythingHasBeenReceived()) {
$this->deferred->resolve();
}
})->then(function () {
if (isset($this->cancel_timer)) {
$this->loop->cancelTimer($this->cancel_timer);
unset($this->cancel_timer);
}
})->done(function () {
$response = call_user_func($this->then_callback, $this->data);
$headers = ['Content-Type' => 'text/plain'];
$this->response->writeHead(200, $headers);
$this->response->end($response);
}, function () {
$headers = ['Content-Type' => 'text/plain'];
$this->response->writeHead(404, $headers);
$this->response->end("Failed");
});
if (empty($this->requests)) {
$this->deferred->resolve();
} else {
$this->registerCancelTimer();
foreach ($this->requests as $request) {
$request->end();
}
}
return $this;
}
示例2: close
public function close()
{
if ($this->closed) {
return;
}
$this->loop->cancelTimer($this->timer);
unset($this->queue);
$this->closed = true;
}
示例3: cancelPeriodicTimer
/**
* @param string $name
*/
public function cancelPeriodicTimer($tidOrname)
{
if (!isset($this->registry[$tidOrname])) {
$tid = $this->getTid($tidOrname);
} else {
$tid = $tidOrname;
}
$timer = $this->registry[$tid];
$this->loop->cancelTimer($timer);
unset($this->registry[$tid]);
}
示例4: del
/**
* Remove event listener from event loop.
*
* @param mixed $fd
* @param int $flag
* @return bool
*/
public function del($fd, $flag)
{
switch ($flag) {
case EventInterface::EV_READ:
return $this->_loop->removeReadStream($fd);
case EventInterface::EV_WRITE:
return $this->_loop->removeWriteStream($fd);
case EventInterface::EV_SIGNAL:
return $this->_loop->removeSignal($fd);
case EventInterface::EV_TIMER:
case EventInterface::EV_TIMER_ONCE:
return $this->_loop->cancelTimer($fd);
}
return false;
}
示例5: __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());
}
});
}
示例6: wait
/**
* @param string $captchaId
* @return Promise\Promise
*/
public function wait($captchaId)
{
$deferred = new Promise\Deferred();
$this->loop->addPeriodicTimer($this->requestInterval, function ($timer) use($deferred, $captchaId) {
$request = $this->client->request($this->getResultMethod(), $this->getResultPath(), ['Content-Length' => strlen($this->getResultQuery($captchaId)), 'Content-Type' => 'application/x-www-form-urlencoded']);
$request->on('response', function ($response) use($request, $deferred, $timer) {
/** @var \React\HttpClient\Response $response */
$response->on('data', function ($data, $response) use($request, $deferred, $timer) {
/** @var \GuzzleHttp\Psr7\Stream $data */
/** @var \React\HttpClient\Response $response */
$response->handleEnd();
$answer = $data->getContents();
// stream read
if (!$answer) {
$this->loop->cancelTimer($timer);
$deferred->reject(new ServiceException('ERROR_CONNECTION'));
} elseif (substr($answer, 0, 2) === 'OK') {
$this->loop->cancelTimer($timer);
$deferred->resolve(substr($answer, 3));
} elseif ($answer !== 'CAPCHA_NOT_READY') {
$this->loop->cancelTimer($timer);
$deferred->reject(new ServiceException($answer));
}
});
});
$request->end($this->getResultQuery($captchaId));
});
return $deferred->promise();
}
示例7: cancelPeriodicTimer
/**
* @param TopicInterface $topic
* @param string $name
*/
public function cancelPeriodicTimer(TopicInterface $topic, $name)
{
$namespace = spl_object_hash($topic);
if (isset($this->registry[$namespace][$name])) {
return;
}
$timer = $this->registry[$namespace][$name];
$this->loop->cancelTimer($timer);
unset($this->registry[$namespace][$name]);
}
示例8: postponeMaintenance
/**
* Postpone the maintenance run
*/
public function postponeMaintenance()
{
if ($this->maintenanceTimer) {
$this->eventLoop->cancelTimer($this->maintenanceTimer);
}
$this->maintenanceTimer = $this->eventLoop->addTimer($this->maintenanceInterval, function ($timer) {
$this->runMaintenance();
$this->postponeMaintenance();
});
}
示例9: close
/**
* Method to call when stopping listening to messages.
*/
public function close()
{
if ($this->closed) {
return;
}
$this->emit('end', [$this]);
$this->loop->cancelTimer($this->timer);
$this->removeAllListeners();
unset($this->exchange);
$this->closed = true;
}
示例10: cancelReminder
/**
* Cancel a running timer
*
* @param \Phergie\Irc\Plugin\React\Command\CommandEvent $event
* @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
*/
public function cancelReminder(Event $event, Queue $queue)
{
extract($this->parseReminder($event));
if (isset($this->activeTimers[$nick][$name])) {
$this->loop->cancelTimer($this->activeTimers[$nick][$name]);
unset($this->activeTimers[$nick][$name]);
$queue->{$command}($source, "{$nick}: The {$name} reminder has been cancelled.");
} else {
$queue->{$command}($source, "{$nick}: That reminder isn't running.");
}
}
示例11: resolve
function resolve($time, LoopInterface $loop)
{
return new Promise(function ($resolve) use($loop, $time, &$timer) {
// resolve the promise when the timer fires in $time seconds
$timer = $loop->addTimer($time, function () use($time, $resolve) {
$resolve($time);
});
}, function ($resolveUnused, $reject) use(&$timer, $loop) {
// cancelling this promise will cancel the timer and reject
$loop->cancelTimer($timer);
$reject(new \RuntimeException('Timer cancelled'));
});
}
示例12: onEnd
/**
*
*/
protected function onEnd()
{
if ($this->requestTimer !== null && $this->loop->isTimerActive($this->requestTimer)) {
$this->loop->cancelTimer($this->requestTimer);
}
if ($this->connectionTimer !== null && $this->loop->isTimerActive($this->connectionTimer)) {
$this->loop->cancelTimer($this->connectionTimer);
}
$this->loop->futureTick(function () {
if ($this->httpResponse === null) {
$this->deferred->reject($this->error);
}
});
}
示例13: handleClose
/**
* Handles closing of the stream.
*/
private function handleClose()
{
foreach ($this->timer as $timer) {
$this->loop->cancelTimer($timer);
}
$connection = $this->connection;
$this->isConnecting = false;
$this->isDisconnecting = false;
$this->isConnected = false;
$this->connection = null;
$this->stream = null;
if ($connection !== null) {
$this->emit('close', [$connection, $this]);
}
}
示例14: closure
/**
* @param Server $server
* @param LoopInterface $loop
*/
protected function closure(Server $server, LoopInterface $loop)
{
$this->logger->notice('Stopping server ...');
foreach ($this->serverPushHandlerRegistry->getPushers() as $handler) {
$handler->close();
$this->logger->info(sprintf('Stop %s push handler', $handler->getName()));
}
$server->emit('end');
$server->shutdown();
foreach ($this->periodicRegistry->getPeriodics() as $periodic) {
if ($periodic instanceof TimerInterface && $loop->isTimerActive($periodic)) {
$loop->cancelTimer($periodic);
}
}
$loop->stop();
$this->logger->notice('Server stopped !');
}
示例15: cancel
/**
* Cancel an existing timer/stream watcher
*
* @param int $watcherId
*/
public function cancel($watcherId)
{
if (isset($this->watchers[$watcherId])) {
list($type, $data) = $this->watchers[$watcherId];
switch ($type) {
case self::WATCHER_TYPE_READ:
$this->reactor->removeReadStream($data);
break;
case self::WATCHER_TYPE_WRITE:
$this->reactor->removeWriteStream($data);
break;
case self::WATCHER_TYPE_TIMER:
$this->reactor->cancelTimer($data);
break;
}
}
unset($this->watchers[$watcherId], $this->disabledWatchers[$watcherId]);
}