Amp\Artax\ChunkingIterator::current PHP Method

current() public method

public current ( )
    public function current()
    {
        if ($this->isLastChunk) {
            return $this->applyChunkEncoding('');
        } elseif (($current = $this->iterator->current()) === '') {
            return null;
        } elseif (is_string($current)) {
            return $this->applyChunkEncoding($current);
        } elseif ($current instanceof Promise) {
            $promisor = new Deferred();
            $current->when(function ($error, $result) use($promisor) {
                if ($error) {
                    $promisor->fail($error);
                } elseif (is_string($result)) {
                    $promisor->succeed($this->applyChunkEncoding($result));
                } else {
                    $promisor->fail(new \DomainException(sprintf('Only string/Promise elements may be chunked; %s provided', gettype($result))));
                }
            });
            return $promisor->promise();
        } else {
            // @TODO How to react to an invalid type returned from an iterator?
            return null;
        }
    }