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


PHP Promise\reject函数代码示例

本文整理汇总了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]);
 }
开发者ID:shsrain,项目名称:ypyzApi,代码行数:7,代码来源:ArrayCache.php

示例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;
 }
开发者ID:clue,项目名称:redis-react,代码行数:39,代码来源:Factory.php

示例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);
     }
 }
开发者ID:shsrain,项目名称:ypyzApi,代码行数:25,代码来源:FilesystemFactory.php

示例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'));
    });
}
开发者ID:clue,项目名称:promise-stream-react,代码行数:36,代码来源:functions.php

示例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));
 }
开发者ID:im286er,项目名称:ent,代码行数:9,代码来源:RejectTestTrait.php

示例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));
 }
开发者ID:gai00,项目名称:socket-client,代码行数:8,代码来源:UnixConnector.php

示例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));
 }
开发者ID:Masterfion,项目名称:plugin-sonos,代码行数:9,代码来源:ResolveTestTrait.php

示例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);
 }
开发者ID:clue,项目名称:connection-manager-extra,代码行数:9,代码来源:ConnectionManagerRandomTest.php

示例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);
 }
开发者ID:clue,项目名称:promise-timeout,代码行数:9,代码来源:FunctionTimeoutTest.php

示例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);
 }
开发者ID:clue,项目名称:connection-manager-extra,代码行数:9,代码来源:ConnectionManagerRepeatTest.php

示例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);
 }
开发者ID:verzulli,项目名称:palestra,代码行数:10,代码来源:TcpConnector.php

示例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);
 }
开发者ID:clue,项目名称:connection-manager-extra,代码行数:9,代码来源:ConnectionManagerSelective.php

示例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);
 }
开发者ID:clue,项目名称:buzz-react,代码行数:10,代码来源:SenderTest.php

示例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);
     }
 }
开发者ID:jahudka,项目名称:react-mpd,代码行数:16,代码来源:Native.php

示例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();
     });
 }
开发者ID:WyriHaximus,项目名称:php-travis-client,代码行数:12,代码来源:Broadcast.php


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