as_reader.Rd
as_reader
turns an existing object into a readable stream.
Coercion can be used when you want to create a readable stream from a known
data source. In general, this is the easiest way to create a readable stream.
As an S3 generic, as_reader
holds methods for:
base::data.frame
: creates a generator function that pushes
one row of a data.frame at a time into the stream
connection: pulls chunks from a connection line by line, closing when a 0-length string is returned
promises::promise
: uses the eventual output (onFulfilled
value) of the promise as a chunk source.
If a rejection occurs, the stream will be errored.
default: create an iterator through coro::as_iterator
,
which is then used to supply chunks to the stream
as_reader(x, queue_strategy)
object to coerce
optionally specify the queue strategy of the stream
# create a readable stream from a numeric vector
reader <- as_reader(1:10)
on(reader, "data", print)