本文整理汇总了PHP中React\Promise\Deferred::reject方法的典型用法代码示例。如果您正苦于以下问题:PHP Deferred::reject方法的具体用法?PHP Deferred::reject怎么用?PHP Deferred::reject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类React\Promise\Deferred
的用法示例。
在下文中一共展示了Deferred::reject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processDeferred
/**
* Change the target owner
* @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("Changing '{$description->getTarget()}' owner to '{$description->getOwner()}'", Notification::PRIORITY_NORMAL));
if ($this->getFileSystem()->changeOwner($description->getTarget(), $description->getOwner())) {
$deferred->resolve("Changed '{$description->getTarget()}' owner to '{$description->getOwner()}' successfully");
return;
}
} catch (\Exception $e) {
// do noting, we reject below
$deferred->reject("Failed to change the owner of {$description->getTarget()}: " . $e->getMessage());
return;
}
$deferred->reject("Failed to change the owner of {$description->getTarget()} to {$description->getOwner()}");
}
示例2: executeRequest
private function executeRequest($method, $uri, $body = null)
{
$deferred = new Deferred();
$request = $this->client->request($method, $this->buildUrl($uri), array('Content-Length' => strlen($body), 'Authorization' => 'Basic ' . base64_encode($this->options['user'] . ':' . $this->options['password']), 'Content-Type' => 'application/json'));
$request->writeHead();
$request->on('error', function ($error) use($uri, $deferred) {
$deferred->reject(sprintf('Error while doing the request on %s : %s', $uri, $error->getMessage()));
});
$request->on('response', function (Response $response) use($deferred) {
if ($response->getCode() < 200 || $response->getCode() >= 400) {
$deferred->reject(sprintf('The response is not as expected (status code %s, message is %s)', $response->getCode(), $response->getReasonPhrase()));
}
$response->on('error', function ($error) use($deferred) {
$deferred->reject($error->getMessage());
});
$data = (object) array('data' => '');
$response->on('data', function ($chunk) use($data) {
$data->data .= $chunk;
});
$response->on('end', function () use($deferred, $data) {
$deferred->resolve($data->data);
});
});
$request->end($body);
return $deferred->promise();
}
示例3: createInternalAsync
protected function createInternalAsync($host, $docroot, $router)
{
$deferred = new Deferred();
$process = new BuiltinServer($host, $docroot, $router, $this->php);
$process->start($this->loop);
$process->on('exit', function ($code) use($deferred) {
$this->stderr->write("Process exit with code {$code}\n");
$deferred->reject();
});
$process->stdin->close();
$process->stdout->close();
$process->stderr->on('data', function ($output) use($deferred) {
$this->stderr->write($output);
$deferred->reject();
});
$timer = new Deferred();
$this->loop->addTimer(0.05, function () use($timer, $process) {
if (DIRECTORY_SEPARATOR === '\\') {
// Pipes opened by proc_open() can break stream_select() loop in Windows.
// This fix might do the trick...
$process->stderr->close();
}
$timer->resolve($process);
});
return \React\Promise\race([$deferred->promise(), $timer->promise()])->then(null, function () use($process) {
$process->terminate();
return new RejectedPromise();
});
}
示例4: doQuery
public function doQuery($nameserver, $transport, $queryData, $name)
{
$parser = $this->parser;
$loop = $this->loop;
$response = new Message();
$deferred = new Deferred();
$retryWithTcp = function () use($nameserver, $queryData, $name) {
return $this->doQuery($nameserver, 'tcp', $queryData, $name);
};
$timer = $this->loop->addTimer($this->timeout, function () use(&$conn, $name, $deferred) {
$conn->close();
$deferred->reject(new TimeoutException(sprintf("DNS query for %s timed out", $name)));
});
$conn = $this->createConnection($nameserver, $transport);
$conn->on('data', function ($data) use($retryWithTcp, $conn, $parser, $response, $transport, $deferred, $timer) {
$responseReady = $parser->parseChunk($data, $response);
if (!$responseReady) {
return;
}
$timer->cancel();
if ($response->header->isTruncated()) {
if ('tcp' === $transport) {
$deferred->reject(new BadServerException('The server set the truncated bit although we issued a TCP request'));
} else {
$conn->end();
$deferred->resolve($retryWithTcp());
}
return;
}
$conn->end();
$deferred->resolve($response);
});
$conn->write($queryData);
return $deferred->promise();
}
示例5: doQuery
public function doQuery($nameserver, $queryData, $name)
{
$that = $this;
$parser = $this->parser;
$loop = $this->loop;
$deferred = new Deferred(function ($_, $reject) use(&$conn, &$timer, $name) {
$conn->close();
$timer->cancel();
$reject(new \RuntimeException(sprintf("DNS query for %s cancelled", $name)));
});
$timer = $this->loop->addTimer($this->timeout, function () use(&$conn, $name, $deferred) {
$conn->close();
$deferred->reject(new TimeoutException(sprintf("DNS query for %s timed out", $name)));
});
$conn = $this->factory->createSender();
$conn->on('message', function ($data) use($conn, $parser, $deferred, $timer) {
$response = new Message();
$responseReady = $parser->parseChunk($data, $response);
$conn->close();
$timer->cancel();
if (!$responseReady) {
$deferred->reject(new BadServerException('Invalid response received'));
return;
}
if ($response->header->isTruncated()) {
$deferred->reject(new BadServerException('The server set the truncated bit although we issued a TCP request'));
return;
}
$deferred->resolve($response);
});
$conn->send($queryData, $nameserver);
return $deferred->promise();
}
示例6: call
/**
* @param $channel
* @param string $message
* @return DeferredPromise
*/
public function call($channel, $message)
{
$loop = LoopFactory::create();
$factory = new StompFactory($loop);
$client = $factory->createClient();
$deferred = new Deferred();
$timer = $loop->addTimer(2, function () use($deferred, $client) {
$client->disconnect();
$deferred->reject(new RpcTimeIsOutException());
});
$client->connect()->then(function (StompClient $client) use($message, $channel, $loop, $deferred, $timer) {
$rpcReceiver = function (Frame $frame) use($deferred, $timer, $client) {
$timer->cancel();
$client->disconnect();
try {
$deferred->resolve($frame);
} catch (\Exception $e) {
$deferred->reject($e);
}
};
$client->sendToTemp($channel, $message, [], $rpcReceiver);
}, function () use($deferred, $client) {
$client->disconnect();
$deferred->reject(new \RuntimeException('Error start rpc connection'));
});
$loop->run();
return $deferred->promise();
}
示例7: testHttpError
public function testHttpError()
{
$d = new Deferred();
$d->reject(new RuntimeException('error'));
$this->browser->expects($this->once())->method('get')->with($this->equalTo('http://a/path?key=mykey&hash=myhash&action=status'), array())->will($this->returnValue($d->promise()));
$this->expectPromiseReject($this->client->status());
}
示例8: sendAsyncRequest
/**
* {@inheritdoc}
*/
public function sendAsyncRequest(RequestInterface $request)
{
$requestStream = $this->buildReactRequest($request);
$deferred = new Deferred();
$requestStream->on('error', function (\Exception $error) use($deferred, $request) {
$deferred->reject(new RequestException($error->getMessage(), $request, $error));
});
$requestStream->on('response', function (ReactResponse $response = null) use($deferred, $requestStream, $request) {
$bodyStream = null;
$response->on('data', function ($data) use(&$bodyStream) {
if ($data instanceof StreamInterface) {
$bodyStream = $data;
} else {
$bodyStream->write($data);
}
});
$response->on('end', function (\Exception $error = null) use($deferred, $request, $response, &$bodyStream) {
$bodyStream->rewind();
$psr7Response = $this->messageFactory->createResponse($response->getCode(), $response->getReasonPhrase(), $response->getHeaders(), $bodyStream, $response->getVersion());
if (null !== $error) {
$deferred->reject(new HttpException($error->getMessage(), $request, $psr7Response, $error));
} else {
$deferred->resolve($psr7Response);
}
});
});
$requestStream->end((string) $request->getBody());
$promise = new ReactPromiseAdapter($deferred->promise());
$this->loop->run();
return $promise;
}
示例9: connect
public function connect($timeout = 5)
{
if ($this->connectDeferred) {
return $this->connectDeferred->promise();
}
$this->connectionStatus = 'connecting';
$promise = new Deferred();
$client = $this;
$loop = $this->loop;
$this->connectDeferred = $promise;
$this->connectDeferred->then(function () use($client) {
$client->setConnectionStatus('connected');
});
$timer = $this->loop->addTimer($timeout, function () use($client, $promise) {
$promise->reject(new ConnectionException('Connection timeout'));
$client->resetConnectDeferred();
$client->setConnectionStatus('not-connected');
});
$this->on('connect', function ($client) use($timer, $promise) {
$timer->cancel();
$promise->resolve($client);
});
$frame = $this->packageCreator->connect($this->options['vhost'], $this->options['login'], $this->options['passcode']);
$this->output->sendFrame($frame);
return $this->connectDeferred->promise();
}
示例10: sendAsyncRequest
/**
* {@inheritdoc}
*/
public function sendAsyncRequest(RequestInterface $request)
{
$reactRequest = $this->buildReactRequest($request);
$deferred = new Deferred();
$reactRequest->on('error', function (\Exception $error) use($deferred, $request) {
$deferred->reject(new RequestException($error->getMessage(), $request, $error));
});
$reactRequest->on('response', function (ReactResponse $reactResponse = null) use($deferred, $reactRequest, $request) {
$bodyStream = $this->streamFactory->createStream();
$reactResponse->on('data', function ($data) use(&$bodyStream) {
$bodyStream->write((string) $data);
});
$reactResponse->on('end', function (\Exception $error = null) use($deferred, $request, $reactResponse, &$bodyStream) {
$response = $this->buildResponse($reactResponse, $bodyStream);
if (null !== $error) {
$deferred->reject(new HttpException($error->getMessage(), $request, $response, $error));
} else {
$deferred->resolve($response);
}
});
});
$reactRequest->end((string) $request->getBody());
$promise = new Promise($deferred->promise());
$promise->setLoop($this->loop);
return $promise;
}
示例11: loadEtcResolvConf
public function loadEtcResolvConf($filename)
{
if (!file_exists($filename)) {
return When::reject(new \InvalidArgumentException("The filename for /etc/resolv.conf given does not exist: {$filename}"));
}
try {
$deferred = new Deferred();
$fd = fopen($filename, 'r');
stream_set_blocking($fd, 0);
$contents = '';
$stream = new Stream($fd, $this->loop);
$stream->on('data', function ($data) use(&$contents) {
$contents .= $data;
});
$stream->on('end', function () use(&$contents, $deferred) {
$deferred->resolve($contents);
});
$stream->on('error', function ($error) use($deferred) {
$deferred->reject($error);
});
return $deferred->promise();
} catch (\Exception $e) {
return When::reject($e);
}
}
示例12: go
/** @internal */
public function go(Process $process)
{
$this->deferred = $deferred = new Deferred();
$this->process = $process;
$buffered = null;
$process->stdout->on('data', function ($data) use(&$buffered) {
if ($data !== '') {
$buffered .= $data;
}
});
$process->on('exit', function ($code) use($deferred) {
if ($code !== 0) {
$deferred->reject($code);
} else {
$deferred->resolve();
}
});
$that = $this;
$this->promise = $deferred->promise()->then(function () use(&$buffered, $that) {
if ($buffered === null) {
$buffered = true;
} else {
$buffered = $that->parseValue(trim($buffered));
}
return $buffered;
});
}
示例13: show
/**
* @returns \React\Promise\Promise
*/
public function show()
{
$deferred = new Deferred();
$this->io->out('hello');
$deferred->reject(false);
return $deferred->promise();
}
示例14: 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]));
}
}
示例15: createPromiseRejected
protected function createPromiseRejected($value = null, $delay = 0.01)
{
$deferred = new Deferred();
$this->loop->addTimer($delay, function () use($deferred, $value) {
$deferred->reject($value);
});
return $deferred->promise();
}