src/Text/TextReader.php
public function scan(string $format, float $timeout = 0): \Generator
    {
        // Read from the stream chunk by chunk, attempting to satisfy the format
        // string each time until the format successfully parses or the end of
        // the stream is reached.
        while (true) {
            $result = sscanf((string) $this->buffer, $format . '%n');
            $length = $result ? array_pop($result) : null;

            // If the format string was satisfied, consume the used characters and
            // return the parsed results.
            if ($length !== null && $length < $this->buffer->getLength()) {
                $this->buffer->shift($length);
                return $result;
            }

            // Read more into the buffer if possible.
            if ($this->stream->isReadable()) {
                $this->buffer->push(yield from $this->stream->read(0, null, $timeout));
            } else {
                // Format string can't be satisfied.
                return [];
            }
        }
    }
public function scan(string $format, float $timeout = 0): \Generator
    {
        // Read from the stream chunk by chunk, attempting to satisfy the format
        // string each time until the format successfully parses or the end of
        // the stream is reached.
        while (true) {
            $result = sscanf((string) $this->buffer, $format . '%n');
            $length = $result ? array_pop($result) : null;

            // If the format string was satisfied, consume the used characters and
            // return the parsed results.
            if ($length !== null && $length < $this->buffer->getLength()) {
                $this->buffer->shift($length);
                return $result;
            }

            // Read more into the buffer if possible.
            if ($this->stream->isReadable()) {
                $this->buffer->push(yield from $this->stream->read(0, null, $timeout));
            } else {
                // Format string can't be satisfied.
                return [];
            }
        }
    }
@coroutine

Reads and parses characters from the stream according to a format.

The format string is of the same format as `sscanf()`.

@param string $format The parse format.
@param float|int $timeout Number of seconds until the returned promise is rejected with a TimeoutException
if no data is received. Use 0 for no timeout.

@return \Generator

@resolve array An array of parsed values.

@throws \Icicle\Awaitable\Exception\TimeoutException If the operation times out.
@throws \Icicle\Stream\Exception\UnreadableException If the stream is no longer readable.
@throws \Icicle\Stream\Exception\ClosedException If the stream is unexpectedly closed.

@see http://php.net/sscanf