當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Deferred::reject方法代碼示例

本文整理匯總了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()}");
 }
開發者ID:TheFoundryVisionmongers,項目名稱:Masonry-Module-FileSystem,代碼行數:24,代碼來源:Worker.php

示例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();
 }
開發者ID:aashley,項目名稱:RabbitMQ-Management-API-Client,代碼行數:26,代碼來源:AsyncAPIClient.php

示例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();
     });
 }
開發者ID:mpyw,項目名稱:php-hyper-builtin-server,代碼行數:29,代碼來源:BuiltinServerFactory.php

示例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();
 }
開發者ID:shsrain,項目名稱:ypyzApi,代碼行數:35,代碼來源:Executor.php

示例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();
 }
開發者ID:clue,項目名稱:mdns-react,代碼行數:33,代碼來源:MulticastExecutor.php

示例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();
 }
開發者ID:BobrD,項目名稱:ProcessManager,代碼行數:33,代碼來源:RpcClient.php

示例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());
 }
開發者ID:clue,項目名稱:solusvm-api-react,代碼行數:7,代碼來源:ClientTest.php

示例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;
 }
開發者ID:shulard,項目名稱:httplug-react-client,代碼行數:34,代碼來源:ReactHttpClient.php

示例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();
 }
開發者ID:omissis,項目名稱:stomp,代碼行數:26,代碼來源:Client.php

示例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;
 }
開發者ID:php-http,項目名稱:react-adapter,代碼行數:29,代碼來源:Client.php

示例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);
     }
 }
開發者ID:jxw7733,項目名稱:zphpdemo,代碼行數:25,代碼來源:FilesystemFactory.php

示例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;
     });
 }
開發者ID:clue,項目名稱:zenity-react,代碼行數:28,代碼來源:BaseZen.php

示例13: show

 /**
  * @returns \React\Promise\Promise
  */
 public function show()
 {
     $deferred = new Deferred();
     $this->io->out('hello');
     $deferred->reject(false);
     return $deferred->promise();
 }
開發者ID:thinkingmedia,項目名稱:cakephp-installer,代碼行數:10,代碼來源:Prompt.php

示例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]));
     }
 }
開發者ID:jderusse,項目名稱:async,代碼行數:20,代碼來源:SymfonyProcess.php

示例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();
 }
開發者ID:clue,項目名稱:block-react,代碼行數:8,代碼來源:bootstrap.php


注:本文中的React\Promise\Deferred::reject方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。