本文整理汇总了PHP中React\Promise\Deferred::notify方法的典型用法代码示例。如果您正苦于以下问题:PHP Deferred::notify方法的具体用法?PHP Deferred::notify怎么用?PHP Deferred::notify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类React\Promise\Deferred
的用法示例。
在下文中一共展示了Deferred::notify方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processDeferred
/**
* Load contents of a template, replace placeholders with passed values and save to a target file
*
* @param Deferred $deferred
* @param TaskInterface $task
* @return bool
*/
protected function processDeferred(Deferred $deferred, TaskInterface $task)
{
yield;
/** @var Description $description */
$description = $task->getDescription();
try {
$deferred->notify(new Notification("Loading template {$description->getTemplate()}'", Notification::PRIORITY_NORMAL));
$contents = $this->getFileSystem()->getFileContents($description->getTemplate());
$keyValuePairs = [];
foreach ($description->getParams() as $key => $value) {
$keyValuePairs["{{ " . $key . " }}"] = $value;
}
$processedContents = strtr($contents, $keyValuePairs);
$deferred->notify("File content generated, saving to {$description->getTarget()}");
if ($this->getFileSystem()->write($description->getTarget(), $processedContents)) {
$deferred->resolve("Created '{$description->getTarget()}' from template '{$description->getTemplate()}'");
return;
}
} catch (\Exception $e) {
$deferred->notify("Could not write template: " . $e->getMessage());
}
$deferred->reject("Could not create '{$description->getTarget()}' from template '{$description->getTemplate()}'");
}
示例2: startPendingTasks
/**
* Starts pending tasks end move them from the pendingQueue to the runningQueue
*/
private function startPendingTasks()
{
while (count($this->runningTasks) < $this->concurrencyLimit && !$this->pendingTasks->isEmpty()) {
/** @var TaskInterface $task */
$task = $this->pendingTasks->dequeue();
$task->start()->progress(function (Event $notification) {
$this->deferred->notify($notification);
})->always(function () use($task) {
$this->finishedTasks[] = $task;
$this->deferred->notify(new TaskFinishedEvent($this, $task));
});
$this->deferred->notify(new TaskStartedEvent($this, $task));
$this->runningTasks->enqueue($task);
}
}
示例3: finishResponse
private function finishResponse($request, $value, $hash)
{
unset($this->waitQueue[$hash]);
$result = $value instanceof ResponseInterface ? ['request' => $request, 'response' => $value, 'error' => null] : ['request' => $request, 'response' => null, 'error' => $value];
$this->deferred->notify($result);
}
示例4: Deferred
<?php
use React\Promise\Deferred;
require "vendor/autoload.php";
$deferred = new Deferred();
$deferred->promise()->then(function () {
echo "then\n";
})->always(function () {
echo "always\n";
})->progress(function () {
echo "progress\n";
});
$deferred->notify();
$deferred->reject();
$deferred->resolve();
示例5: tick
/**
* {@inheritdoc}
*/
public function tick()
{
if ($this->firstTick) {
$this->firstTick = false;
$this->deferred->notify(new MessageEvent($this, $this->generator->current()));
} else {
$this->deferred->notify(new MessageEvent($this, $this->generator->send(null)));
}
if (!$this->generator->valid()) {
$this->deferred->resolve(new Event($this));
}
}
示例6: should
public function should($url, $alias = '')
{
if (empty($alias)) {
$alias = $url;
}
$request = $this->client->request('GET', $url);
$this->requests[] = $request;
$request->on('response', function ($response) use($alias) {
$response->on('data', function ($data) use($alias) {
if (empty($data)) {
return;
}
$this->deferred->notify(['part' => $alias, 'data' => $data]);
});
});
return $this;
}
示例7: tick
/**
* {@inheritdoc}
*/
public function tick()
{
if (!$this->process->isRunning() && $this->outputBuffer->isEmpty()) {
usleep(1000);
if ($this->outputBuffer->isEmpty()) {
if ($this->process->isSuccessful()) {
$this->deferred->resolve(new MessageEvent($this, $this->process->getOutput()));
} else {
$this->deferred->reject(new MessageEvent($this, $this->process->getOutput()));
}
return;
}
}
if (!$this->outputBuffer->isEmpty()) {
$this->deferred->notify(new MessageEvent($this, $this->outputBuffer->dequeue()[1]));
}
}
示例8: publishPeriodically
/**
* Calls the given generator periodically and publishes the return value.
*
* @param int $interval
* @param Message $message
* @param callable $generator
*
* @return ExtendedPromiseInterface
*/
public function publishPeriodically($interval, Message $message, callable $generator)
{
if (!$this->isConnected) {
return new RejectedPromise(new \LogicException('The client is not connected.'));
}
$deferred = new Deferred();
$this->timer[] = $this->loop->addPeriodicTimer($interval, function () use($message, $generator, $deferred) {
$this->publish($message->withPayload($generator($message->getTopic())))->then(function ($value) use($deferred) {
$deferred->notify($value);
}, function (\Exception $e) use($deferred) {
$deferred->reject($e);
});
});
return $deferred->promise();
}