本文整理汇总了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;
}
示例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();
}
示例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);
}
示例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();
}
示例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);
}
示例6: progress
/**
* @param mixed $value
*/
public function progress($value)
{
$cleanup = $this->cleanup;
$cleanup($this);
return $this->deferred->progress($value);
}