The controller object passed to the ReadableStream's functions is a list with references to the underlying stream object.

Details

Members:

  • desired_size

  • start_value

Methods:

  • emit

  • enqueue

  • close

  • error

Member desired_size

Reference to streams::ReadableStream$desired_size


Member start_value

The return value of the stream's start function

Examples


                # the start value can be used to store a connection for
# reference during the pull method
r <- ReadableStream$new(
    start = function(controller) {
        x <- file(tempfile())
         if (!isOpen(x)) {
               open(x)
          }
       x
    },
    pull = function(controller) {
        out <- readLines(c$start_value, n = 1L)
       if (length(out) > 0L) {
           c$enqueue(out)
       } else {
           c$close()
       }
    }
)
            


Method enqueue()

Pushes a chunk of data into the stream's internal queue

Arguments

chunk

Data that will be pushed into the stream's queue


Method close()

Order the stream to close when possible.

Specifically, the stream will enter a "close_requested" state. Whenever the internal buffer reaches a size of 0, the stream will stop processing data and will close.

Arguments

chunk

Data that will be pushed into the stream's queue


Method error()

Orders the stream to be put into an errored state.

Arguments

e

Reason given for throwing an error


See also

streams::ReadableStream