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


PHP Deferred::progress方法代码示例

本文整理汇总了PHP中React\Promise\Deferred::progress方法的典型用法代码示例。如果您正苦于以下问题:PHP Deferred::progress方法的具体用法?PHP Deferred::progress怎么用?PHP Deferred::progress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在React\Promise\Deferred的用法示例。


在下文中一共展示了Deferred::progress方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addNextRequest

 /**
  * Adds the next request to pool and tracks what requests need to be
  * dereferenced when completing the pool.
  */
 private function addNextRequest()
 {
     if ($this->isRealized || !$this->iter || !$this->iter->valid()) {
         return false;
     }
     $request = $this->iter->current();
     $this->iter->next();
     if (!$request instanceof RequestInterface) {
         throw new \InvalidArgumentException(sprintf('All requests in the provided iterator must implement ' . 'RequestInterface. Found %s', Core::describeType($request)));
     }
     // Be sure to use "lazy" futures, meaning they do not send right away.
     $request->getConfig()->set('future', 'lazy');
     $this->attachListeners($request, $this->eventListeners);
     $response = $this->client->send($request);
     $hash = spl_object_hash($request);
     $this->waitQueue[$hash] = $response;
     // Use this function for both resolution and rejection.
     $fn = function ($value) use($request, $hash) {
         unset($this->waitQueue[$hash]);
         $result = $value instanceof ResponseInterface ? ['request' => $request, 'response' => $value, 'error' => null] : ['request' => $request, 'response' => null, 'error' => $value];
         $this->deferred->progress($result);
         $this->addNextRequest();
     };
     $response->then($fn, $fn);
     return true;
 }
开发者ID:anyforsoft,项目名称:csua_d8,代码行数:30,代码来源:Pool.php

示例2: search

 public function search($searchTarget = 'ssdp:all', $mx = 2)
 {
     $data = "M-SEARCH * HTTP/1.1\r\n";
     $data .= "HOST: " . self::ADDRESS . "\r\n";
     $data .= "MAN: \"ssdp:discover\"\r\n";
     $data .= "MX: {$mx}\r\n";
     $data .= "ST: {$searchTarget}\r\n";
     $data .= "\r\n";
     $socket = $this->multicast->createSender();
     // TODO: The TTL for the IP packet SHOULD default to 2 and SHOULD be configurable.
     $timer = $this->loop->addTimer($mx, function () use($socket, &$deferred) {
         $deferred->resolve();
         $socket->close();
     });
     $deferred = new Deferred(function () use($socket, &$timer) {
         // canceling resulting promise cancels timer and closes socket
         $timer->cancel();
         $socket->close();
         throw new RuntimeException('Cancelled');
     });
     $that = $this;
     $socket->on('message', function ($data, $remote) use($deferred, $that) {
         $message = $that->parseMessage($data, $remote);
         $deferred->progress($message);
     });
     $socket->send($data, self::ADDRESS);
     return $deferred->promise();
 }
开发者ID:clue,项目名称:ssdp-react,代码行数:28,代码来源:Client.php

示例3: progressIsAnAliasForNotify

 /** @test */
 public function progressIsAnAliasForNotify()
 {
     $deferred = new Deferred();
     $sentinel = new \stdClass();
     $mock = $this->createCallableMock();
     $mock->expects($this->once())->method('__invoke')->with($sentinel);
     $deferred->promise()->then($this->expectCallableNever(), $this->expectCallableNever(), $mock);
     $deferred->progress($sentinel);
 }
开发者ID:hazaveh,项目名称:mySQLtoes,代码行数:10,代码来源:DeferredTest.php

示例4: readLength

 public function readLength($bytes)
 {
     $deferred = new Deferred();
     $oldsize = $this->stream->bufferSize;
     $this->stream->bufferSize = $bytes;
     $buffer = '';
     $fn = function ($data, Stream $stream) use(&$buffer, &$bytes, $deferred, $oldsize, &$fn) {
         $bytes -= strlen($data);
         $buffer .= $data;
         $deferred->progress($data);
         if ($bytes === 0) {
             $stream->bufferSize = $oldsize;
             $stream->removeListener('data', $fn);
             $deferred->resolve($buffer);
         } else {
             $stream->bufferSize = $bytes;
         }
     };
     $this->stream->on('data', $fn);
     return $deferred->promise();
 }
开发者ID:Sitronik,项目名称:php-socks,代码行数:21,代码来源:StreamReader.php

示例5: 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->progress($result);
 }
开发者ID:samj1912,项目名称:repo,代码行数:6,代码来源:Pool.php

示例6: progress

 /**
  * @param mixed $value
  */
 public function progress($value)
 {
     $cleanup = $this->cleanup;
     $cleanup($this);
     return $this->deferred->progress($value);
 }
开发者ID:phpCedu,项目名称:reactphp-child-process-messenger,代码行数:9,代码来源:OutstandingCall.php


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