当前位置: 首页>>代码示例>>PHP>>正文


PHP Deferred::notify方法代码示例

本文整理汇总了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()}'");
 }
开发者ID:TheFoundryVisionmongers,项目名称:Masonry-Module-FileSystem,代码行数:30,代码来源:Worker.php

示例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);
     }
 }
开发者ID:jderusse,项目名称:async,代码行数:18,代码来源:MultiTasks.php

示例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);
 }
开发者ID:hellsigner,项目名称:guzzle5-legacy,代码行数:6,代码来源:Pool.php

示例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();
开发者ID:akond,项目名称:reactphp-example,代码行数:15,代码来源:deferred.php

示例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));
     }
 }
开发者ID:jderusse,项目名称:async,代码行数:15,代码来源:Generator.php

示例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;
 }
开发者ID:akond,项目名称:reactphp-example,代码行数:17,代码来源:timed-poll-2.php

示例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]));
     }
 }
开发者ID:jderusse,项目名称:async,代码行数:20,代码来源:SymfonyProcess.php

示例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();
 }
开发者ID:binsoul,项目名称:net-mqtt-client-react,代码行数:24,代码来源:ReactMqttClient.php


注:本文中的React\Promise\Deferred::notify方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。