本文整理汇总了PHP中React\Promise\resolve函数的典型用法代码示例。如果您正苦于以下问题:PHP resolve函数的具体用法?PHP resolve怎么用?PHP resolve使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了resolve函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFetchFile
public function testFetchFile()
{
$response = new Response(200, array(), '# hello', '1.0', 'OK');
$this->expectRequest($this->uri . 'README.md?view=co')->will($this->returnValue(Promise\resolve($response)));
$promise = $this->client->fetchFile('README.md');
$this->expectPromiseResolveWith('# hello', $promise);
}
示例2: testWillWriteAuthCommandIfTargetContainsUserInfo
public function testWillWriteAuthCommandIfTargetContainsUserInfo()
{
$stream = $this->getMockBuilder('React\\Stream\\Stream')->disableOriginalConstructor()->getMock();
$stream->expects($this->once())->method('write')->with("*2\r\n\$4\r\nauth\r\n\$11\r\nhello:world\r\n");
$this->connector->expects($this->once())->method('create')->willReturn(Promise\resolve($stream));
$this->factory->createClient('tcp://hello:world@127.0.0.1');
}
示例3: resolveHostname
private function resolveHostname($host)
{
if (false !== filter_var($host, FILTER_VALIDATE_IP)) {
return Promise\resolve($host);
}
return $this->resolver->resolve($host);
}
示例4: get
public function get($key)
{
if (!isset($this->data[$key])) {
return Promise\reject();
}
return Promise\resolve($this->data[$key]);
}
示例5: testWillNotInvokeProberIfSchemeIsProtocol
public function testWillNotInvokeProberIfSchemeIsProtocol()
{
$stream = $this->getMockBuilder('React\\Stream\\Stream')->disableOriginalConstructor()->getMock();
$this->connector->expects($this->once())->method('create')->will($this->returnValue(Promise\resolve($stream)));
$this->prober->expects($this->never())->method('probe');
$this->expectPromiseResolve($this->factory->createClient('legacy://localhost'));
}
示例6: rejectShouldRejectWithFulfilledPromise
/** @test */
public function rejectShouldRejectWithFulfilledPromise()
{
extract($this->getPromiseTestAdapter());
$mock = $this->createCallableMock();
$mock->expects($this->once())->method('__invoke')->with($this->identicalTo(1));
$promise()->then($this->expectCallableNever(), $mock);
$reject(Promise\resolve(1));
}
示例7: getValues
/**
* {@inheritdoc}
*/
public function getValues() : PromiseInterface
{
$counters = $this->infoProvider->getCounters();
$storage = new \SplObjectStorage();
$storage->attach(new Metric('current_read_streams', (double) $counters['streams']['read']['current']));
$storage->attach(new Metric('current_write_streams', (double) $counters['streams']['write']['current']));
return resolve($storage);
}
示例8: 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));
}
示例9: resolveShouldResolveWithPromisedValue
/** @test */
public function resolveShouldResolveWithPromisedValue()
{
$adapter = $this->getPromiseTestAdapter();
$mock = $this->createCallableMock();
$mock->expects($this->once())->method('__invoke')->with($this->identicalTo(1));
$adapter->promise()->then($mock);
$adapter->resolve(Promise\resolve(1));
}
示例10: 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);
}
示例11: testResolvedWillNotStartTimer
public function testResolvedWillNotStartTimer()
{
$promise = Promise\resolve();
Timer\timeout($promise, 3, $this->loop);
$time = microtime(true);
$this->loop->run();
$time = microtime(true) - $time;
$this->assertLessThan(0.5, $time);
}
示例12: testAwaitOnceWithTimeoutWillResolvemmediatelyAndCleanUpTimeout
public function testAwaitOnceWithTimeoutWillResolvemmediatelyAndCleanUpTimeout()
{
$promise = Promise\resolve(true);
$time = microtime(true);
Block\await($promise, $this->loop, 5.0);
$this->loop->run();
$time = microtime(true) - $time;
$this->assertLessThan(0.1, $time);
}
示例13: resolveSouldProvideDefaultErrorbackToExecutor
/** @test */
public function resolveSouldProvideDefaultErrorbackToExecutor()
{
$executor = $this->createExecutorMock();
$executor->expects($this->once())->method('query')->with($this->anything(), $this->isInstanceOf('React\\Dns\\Query\\Query'))->will($this->returnCallback(function ($nameserver, $query) {
return Promise\resolve();
}));
$resolver = new Resolver('8.8.8.8:53', $executor);
$resolver->resolve('igor.io')->then($this->expectCallableNever());
}
示例14: callQueryCallbackWithAddress
private function callQueryCallbackWithAddress($address)
{
return $this->returnCallback(function ($nameserver, $query) use($address) {
$response = new Message();
$response->header->set('qr', 1);
$response->questions[] = new Record($query->name, $query->type, $query->class);
$response->answers[] = new Record($query->name, $query->type, $query->class, 3600, $address);
return Promise\resolve($response);
});
}
示例15: 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);
}
}