本文整理汇总了PHP中React\Promise\reject函数的典型用法代码示例。如果您正苦于以下问题:PHP reject函数的具体用法?PHP reject怎么用?PHP reject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了reject函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
public function get($key)
{
if (!isset($this->data[$key])) {
return Promise\reject();
}
return Promise\resolve($this->data[$key]);
}
示例2: createClient
/**
* create redis client connected to address of given redis instance
*
* @param string|null $target
* @return \React\Promise\PromiseInterface resolves with Client or rejects with \Exception
*/
public function createClient($target = null)
{
try {
$parts = $this->parseUrl($target);
} catch (InvalidArgumentException $e) {
return Promise\reject($e);
}
$protocol = $this->protocol;
$promise = $this->connector->create($parts['host'], $parts['port'])->then(function (Stream $stream) use($protocol) {
return new StreamingClient($stream, $protocol->createResponseParser(), $protocol->createSerializer());
});
if (isset($parts['auth'])) {
$promise = $promise->then(function (StreamingClient $client) use($parts) {
return $client->auth($parts['auth'])->then(function () use($client) {
return $client;
}, function ($error) use($client) {
$client->close();
throw $error;
});
});
}
if (isset($parts['db'])) {
$promise = $promise->then(function (StreamingClient $client) use($parts) {
return $client->select($parts['db'])->then(function () use($client) {
return $client;
}, function ($error) use($client) {
$client->close();
throw $error;
});
});
}
return $promise;
}
示例3: loadEtcResolvConf
public function loadEtcResolvConf($filename)
{
if (!file_exists($filename)) {
return Promise\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 Promise\reject($e);
}
}
示例4: first
/**
* Creates a `Promise` which resolves with the first event data
*
* @param ReadableStreamInterface|WritableStreamInterface $stream
* @param string $event
* @return CancellablePromiseInterface Promise<mixed, Exception>
*/
function first(EventEmitterInterface $stream, $event = 'data')
{
if ($stream instanceof ReadableStreamInterface) {
// readable or duplex stream not readable => already closed
// a half-open duplex stream is considered closed if its readable side is closed
if (!$stream->isReadable()) {
return Promise\reject(new \RuntimeException('Stream already closed'));
}
} elseif ($stream instanceof WritableStreamInterface) {
// writable-only stream (not duplex) not writable => already closed
if (!$stream->isWritable()) {
return Promise\reject(new \RuntimeException('Stream already closed'));
}
}
return new Promise\Promise(function ($resolve, $reject) use($stream, $event, &$listener) {
$listener = function ($data) use($stream, $event, &$listener, $resolve) {
$stream->removeListener($event, $listener);
$resolve($data);
};
$stream->on($event, $listener);
$stream->on('close', function () use($stream, $event, $listener, $reject) {
$stream->removeListener($event, $listener);
$reject(new \RuntimeException('Stream closed'));
});
}, function ($_, $reject) use($stream, $event, &$listener) {
$stream->removeListener($event, $listener);
$reject(new \RuntimeException('Operation cancelled'));
});
}
示例5: rejectShouldRejectWithRejectedPromise
/** @test */
public function rejectShouldRejectWithRejectedPromise()
{
extract($this->getPromiseTestAdapter());
$mock = $this->createCallableMock();
$mock->expects($this->once())->method('__invoke')->with($this->identicalTo(1));
$promise()->then($this->expectCallableNever(), $mock);
$reject(Promise\reject(1));
}
示例6: create
public function create($path, $unusedPort = 0)
{
$resource = @stream_socket_client('unix://' . $path, $errno, $errstr, 1.0);
if (!$resource) {
return Promise\reject(new RuntimeException('Unable to connect to unix domain socket "' . $path . '": ' . $errstr, $errno));
}
return Promise\resolve(new Stream($resource, $this->loop));
}
示例7: resolveShouldRejectWhenResolvedWithRejectedPromise
/** @test */
public function resolveShouldRejectWhenResolvedWithRejectedPromise()
{
$adapter = $this->getPromiseTestAdapter();
$mock = $this->createCallableMock();
$mock->expects($this->once())->method('__invoke')->with($this->identicalTo(1));
$adapter->promise()->then($this->expectCallableNever(), $mock);
$adapter->resolve(Promise\reject(1));
}
示例8: testWillTryAllIfEachRejects
public function testWillTryAllIfEachRejects()
{
$rejected = Promise\reject(new \RuntimeException('nope'));
$connector = $this->getMock('React\\SocketClient\\ConnectorInterface');
$connector->expects($this->exactly(2))->method('create')->with('google.com', 80)->willReturn($rejected);
$cm = new ConnectionManagerRandom(array($connector, $connector));
$promise = $cm->create('google.com', 80);
$this->assertPromiseReject($promise);
}
示例9: testRejectedWillNotStartTimer
public function testRejectedWillNotStartTimer()
{
$promise = Promise\reject();
Timer\timeout($promise, 3, $this->loop);
$time = microtime(true);
$this->loop->run();
$time = microtime(true) - $time;
$this->assertLessThan(0.5, $time);
}
示例10: testTwoTriesWillStartTwoConnectionAttempts
public function testTwoTriesWillStartTwoConnectionAttempts()
{
$promise = Promise\reject(new \RuntimeException('nope'));
$connector = $this->getMock('React\\SocketClient\\ConnectorInterface');
$connector->expects($this->exactly(2))->method('create')->with('google.com', 80)->willReturn($promise);
$cm = new ConnectionManagerRepeat($connector, 2);
$promise = $cm->create('google.com', 80);
$this->assertPromiseReject($promise);
}
示例11: checkConnectedSocket
/** @internal */
public function checkConnectedSocket($socket)
{
// The following hack looks like the only way to
// detect connection refused errors with PHP's stream sockets.
if (false === stream_socket_get_name($socket, true)) {
return Promise\reject(new ConnectionException('Connection refused'));
}
return Promise\resolve($socket);
}
示例12: create
public function create($host, $port)
{
try {
$connector = $this->getConnectorForTarget($host, $port);
} catch (UnderflowException $e) {
return Promise\reject($e);
}
return $connector->create($host, $port);
}
示例13: testSenderRejection
public function testSenderRejection()
{
$connector = $this->getMock('React\\SocketClient\\ConnectorInterface');
$connector->expects($this->once())->method('create')->willReturn(Promise\reject(new RuntimeException('Rejected')));
$sender = Sender::createFromLoopConnectors($this->loop, $connector);
$request = new Request('GET', 'http://www.google.com/');
$promise = $sender->send($request, $this->getMock('Clue\\React\\Buzz\\Message\\MessageFactory'));
$this->setExpectedException('RuntimeException');
Block\await($promise, $this->loop);
}
示例14: send
/**
* @param string $data
* @return PromiseInterface
* @throws Exception
*/
public function send($data)
{
try {
$this->connect();
stream_set_blocking($this->sock, true);
fwrite($this->sock, $data);
return Promise\resolve();
} catch (\Exception $e) {
return Promise\reject($e);
}
}
示例15: refresh
public function refresh() : PromiseInterface
{
return $this->getTransport()->request('repos/' . $this->repositoryId() . '/branches')->then(function ($json) {
foreach ($json['broadcasts'] as $broadcast) {
if ($broadcast['id'] != $this->id()) {
continue;
}
return resolve($this->getTransport()->getHydrator()->hydrate('Broadcast', $broadcast));
}
return reject();
});
}