当前位置: 首页>>代码示例>>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;未经允许,请勿转载。