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


PHP Generator::valid方法代碼示例

本文整理匯總了PHP中Generator::valid方法的典型用法代碼示例。如果您正苦於以下問題:PHP Generator::valid方法的具體用法?PHP Generator::valid怎麽用?PHP Generator::valid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Generator的用法示例。


在下文中一共展示了Generator::valid方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: resume

 public function resume($params = null)
 {
     $this->generator->send($params);
     if (!$this->generator->valid()) {
         $this->closed = true;
     }
     return $this->generator->current();
 }
開發者ID:panlatent,項目名稱:coroutine,代碼行數:8,代碼來源:Coroutine.php

示例2: tick

 /**
  * {@inheritdoc}
  */
 public function tick()
 {
     if ($this->firstTick) {
         $this->firstTick = false;
         $this->deferred->notify(new MessageEvent($this, $this->generator->current()));
     } else {
         $this->deferred->notify(new MessageEvent($this, $this->generator->send(null)));
     }
     if (!$this->generator->valid()) {
         $this->deferred->resolve(new Event($this));
     }
 }
開發者ID:jderusse,項目名稱:async,代碼行數:15,代碼來源:Generator.php

示例3: reduce

 /**
  * When you need to return Result from your function, and it also depends on another
  * functions returning Results, you can make it a generator function and yield
  * values from dependant functions, this pattern makes code less bloated with
  * statements like this:
  * $res = something();
  * if ($res instanceof Ok) {
  *     $something = $res->unwrap();
  * } else {
  *     return $res;
  * }
  *
  * Instead you can write:
  * $something = (yield something());
  *
  * @see /example.php
  *
  * @param \Generator $resultsGenerator Generator that produces Result instances
  * @return Result
  */
 public static function reduce(\Generator $resultsGenerator)
 {
     /** @var Result $result */
     $result = $resultsGenerator->current();
     while ($resultsGenerator->valid()) {
         if ($result instanceof Err) {
             return $result;
         }
         $tmpResult = $resultsGenerator->send($result->unwrap());
         if ($resultsGenerator->valid()) {
             $result = $tmpResult;
         }
     }
     return $result;
 }
開發者ID:nikita2206,項目名稱:result,代碼行數:35,代碼來源:Result.php

示例4: valid

 public function valid()
 {
     if ($this->_currentGen) {
         return $this->_currentGen->valid();
     }
     return !!$this->current();
 }
開發者ID:Ekhvalov,項目名稱:recordsman,代碼行數:7,代碼來源:RecordSet.php

示例5: next

 /**
  * Examines the value yielded from the generator and prepares the next step in interation.
  *
  * @param mixed $yielded
  */
 private function next($yielded)
 {
     if (!$this->generator->valid()) {
         $result = $this->generator->getReturn();
         if ($result instanceof Awaitable) {
             $this->reject(new AwaitableReturnedError($result));
             return;
         }
         if ($result instanceof Generator) {
             $this->reject(new GeneratorReturnedError($result));
             return;
         }
         $this->resolve($result);
         return;
     }
     $this->busy = true;
     if ($yielded instanceof Generator) {
         $yielded = new self($yielded);
     }
     $this->current = $yielded;
     if ($yielded instanceof Awaitable) {
         $yielded->done($this->send, $this->capture);
     } else {
         Loop\queue($this->send, $yielded);
     }
     $this->busy = false;
 }
開發者ID:icicleio,項目名稱:icicle,代碼行數:32,代碼來源:Coroutine.php

示例6: getReturnOrThrown

 /**
  * Return value that generator has returned or thrown.
  * @return mixed
  */
 public function getReturnOrThrown()
 {
     $this->validateInvalidity();
     if ($this->e === null && $this->g->valid() && !$this->valid()) {
         return $this->g->current();
     }
     if ($this->e) {
         return $this->e;
     }
     return method_exists($this->g, 'getReturn') ? $this->g->getReturn() : null;
 }
開發者ID:mpyw,項目名稱:co,代碼行數:15,代碼來源:GeneratorContainer.php

示例7: checkResult

 private function checkResult(\Generator $generator, Channel $channel)
 {
     if (!$generator->valid()) {
         foreach ($this->actions as list(, $gen, , $undo)) {
             if ($gen && $gen !== $generator) {
                 $undo($gen->current());
             }
         }
         return [$generator->getReturn(), $channel];
     }
     return false;
 }
開發者ID:crystalplanet,項目名稱:redshift,代碼行數:12,代碼來源:ChannelSelector.php

示例8: __construct

 /**
  * @param \Generator $generator
  * @param string $prefix
  */
 public function __construct(\Generator $generator, string $prefix)
 {
     $yielded = $generator->current();
     $prefix .= \sprintf("; %s yielded at key %s", \is_object($yielded) ? \get_class($yielded) : \gettype($yielded), $generator->key());
     if (!$generator->valid()) {
         parent::__construct($prefix);
         return;
     }
     $reflGen = new \ReflectionGenerator($generator);
     $exeGen = $reflGen->getExecutingGenerator();
     if ($isSubgenerator = $exeGen !== $generator) {
         $reflGen = new \ReflectionGenerator($exeGen);
     }
     parent::__construct(\sprintf("%s on line %s in %s", $prefix, $reflGen->getExecutingLine(), $reflGen->getExecutingFile()));
 }
開發者ID:amphp,項目名稱:amp,代碼行數:19,代碼來源:InvalidYieldError.php

示例9: next

 /**
  * Examines the value yielded from the generator and prepares the next step in interation.
  *
  * @param mixed $yielded
  */
 private function next($yielded)
 {
     if (!$this->generator->valid()) {
         $this->resolve($this->generator->getReturn());
         $this->close();
         return;
     }
     if ($yielded instanceof Generator) {
         $yielded = new self($yielded);
     }
     if ($yielded instanceof Awaitable) {
         $yielded->done($this->send, $this->capture);
     } else {
         Loop\queue($this->send, $yielded);
     }
 }
開發者ID:valentinkh1,項目名稱:icicle,代碼行數:21,代碼來源:Coroutine.php

示例10: read

 /**
  * {@inheritdoc}
  */
 public function read($length)
 {
     $this->initializeBeforeRead();
     if (!$this->generator->valid()) {
         return '';
     }
     if ($this->resource->eof()) {
         $this->generator->next();
         if (!$this->generator->valid()) {
             return '';
         }
         $this->resource = $this->generator->current();
         $this->resource->rewind();
     }
     return $this->resource->fread($length);
 }
開發者ID:genkgo,項目名稱:archive-stream,代碼行數:19,代碼來源:Psr7Stream.php

示例11: dispose

 /**
  * Runs the generator to completion then fails the coroutine with the given exception.
  *
  * @param \Throwable $exception
  */
 private function dispose(\Throwable $exception)
 {
     if ($this->generator->valid()) {
         try {
             try {
                 // Ensure generator has run to completion to avoid throws from finally blocks on destruction.
                 do {
                     $this->generator->throw($exception);
                 } while ($this->generator->valid());
             } finally {
                 // Throw from finally to attach any exception thrown from generator as previous exception.
                 throw $exception;
             }
         } catch (\Throwable $exception) {
             // $exception will be used to fail the coroutine.
         }
     }
     $this->fail($exception);
 }
開發者ID:amphp,項目名稱:amp,代碼行數:24,代碼來源:Coroutine.php

示例12: cancel

 /**
  * {@inheritdoc}
  */
 public function cancel(Throwable $reason = null)
 {
     if (null === $reason) {
         $reason = new TerminatedException();
     }
     if (null !== $this->generator) {
         try {
             do {
                 if ($this->current instanceof Awaitable) {
                     $this->current->cancel($reason);
                 }
                 $this->current = $this->generator->throw($reason);
             } while ($this->generator->valid());
         } catch (Throwable $exception) {
             $reason = $exception;
         }
     }
     parent::cancel($reason);
 }
開發者ID:mrxotey,項目名稱:icicle,代碼行數:22,代碼來源:Coroutine.php

示例13: take

/**
 *
 * @param int $n
 * @param \Generator $gen
 *
 * @return \Generator
 */
function take($n, Generator $gen)
{
    while ($n-- > 0 && $gen->valid()) {
        (yield $gen->current());
        $gen->next();
    }
}
開發者ID:domynation,項目名稱:domynation-framework,代碼行數:14,代碼來源:functional.php

示例14: responseCodec

 private function responseCodec(\Generator $filter, InternalRequest $ireq) : \Generator
 {
     while ($filter->valid()) {
         $cur = $filter->send(yield);
         if ($cur !== null) {
             $ireq->responseWriter->send($cur);
         }
     }
     $cur = $filter->getReturn();
     if ($cur !== null) {
         $ireq->responseWriter->send($cur);
     }
     $ireq->responseWriter->send(null);
 }
開發者ID:efueger,項目名稱:aerys,代碼行數:14,代碼來源:Server.php

示例15: hasTokens

 /**
  * Returns true, if there are still tokens left to be generated.
  *
  * If the lexer-generator still has tokens to generate,
  * this returns true and false, if it doesn't
  *
  * @see \Generator->valid
  *
  * @return bool
  */
 protected function hasTokens()
 {
     return $this->tokens->valid();
 }
開發者ID:TeaMeow,項目名稱:Avane,代碼行數:14,代碼來源:Parser.php


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