Future-Buffer

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

    including this match.

    If the stream is closed and there is no remaining data, the returned
    future will yield empty.

    For example, a readline-like operation can be performed by

       $f = $buffer->read_until( "\x0d\x0a" );

 read_unpacked

       $data = await $buffer->read_unpacked( $pack_format );

    Since version 0.03.

    Returns a future which will complete when the buffer contains enough
    data to unpack all of the requested fields using the given pack()
    format. The future will yield a list of all the fields extracted by the
    format.

    If the stream is closed and there is no remaining data, the returned
    future will yield empty.

    Note that because the implementation is shamelessly stolen from
    IO::Handle::Packable the same limitations on what pack formats are
    recognized will apply.

 unread

       $buffer->unread( $data );

    Since version 0.03.

    Prepends more data back into the buffer,

    It is uncommon to need this method, but it may be useful in certain
    situations such as when it is hard to determine upfront how much data
    needs to be read for a single operation, and it turns out too much was
    read. The trailing content past what is needed can be put back for a
    later operation.

    Note that use of this method causes an inherent race condition between
    outstanding read futures and existing data in the buffer. If there are
    no pending futures then this is safe. If there is no existing data
    already in the buffer this is also safe. If neither of these is true
    then a warning is printed indicating that the logic of the caller is
    not well-defined.

TODO

      * An "on-read" event, taking maybe inspiration from
      IO::Async::Stream. This would allow both pull- and push-based
      consumers.

      * Size limitation. Allow an upper bound of stored data, make write
      calls return pending futures until buffer can accept it. Needs
      consideration of unbounded read_until though.

      * Consider extensions of the "read_unpacked" method to handle more
      situations. This may require building a shared CPAN module for doing
      streaming-unpack along with IO::Handle::Packable and other
      situations.

AUTHOR

    Paul Evans <leonerd@leonerd.org.uk>

    Inspired by Ryu::Buffer by Tom Molesworth <TEAM@cpan.org>



( run in 1.968 second using v1.01-cache-2.11-cpan-5837b0d9d2c )