pub struct ReadableStreamDefaultReader<'stream> { /* private fields */ }
Expand description
A ReadableStreamDefaultReader
that can be used to read chunks from a ReadableStream
.
This is returned by the get_reader
method.
When the reader is dropped, it automatically releases its lock.
If the reader still has a pending read request at this point (i.e. if a future returned
by read
is not yet ready), then this will panic. You must either await
all read
futures, or cancel
the stream to discard any pending read
futures.
Implementations§
Source§impl<'stream> ReadableStreamDefaultReader<'stream>
impl<'stream> ReadableStreamDefaultReader<'stream>
Sourcepub fn as_raw(&self) -> &ReadableStreamDefaultReader
pub fn as_raw(&self) -> &ReadableStreamDefaultReader
Acquires a reference to the underlying JavaScript reader.
Sourcepub async fn closed(&self) -> Result<(), JsValue>
pub async fn closed(&self) -> Result<(), JsValue>
Waits for the stream to become closed.
This returns an error if the stream ever errors, or if the reader’s lock is released before the stream finishes closing.
Sourcepub async fn cancel(&mut self) -> Result<(), JsValue>
pub async fn cancel(&mut self) -> Result<(), JsValue>
Cancels the stream, signaling a loss of interest in the stream by a consumer.
Equivalent to ReadableStream.cancel
.
Sourcepub async fn cancel_with_reason(
&mut self,
reason: &JsValue,
) -> Result<(), JsValue>
pub async fn cancel_with_reason( &mut self, reason: &JsValue, ) -> Result<(), JsValue>
Cancels the stream, signaling a loss of interest in the stream by a consumer.
Equivalent to ReadableStream.cancel_with_reason
.
Sourcepub async fn read(&mut self) -> Result<Option<JsValue>, JsValue>
pub async fn read(&mut self) -> Result<Option<JsValue>, JsValue>
Reads the next chunk from the stream’s internal queue.
- If a next
chunk
becomes available, this returnsOk(Some(chunk))
. - If the stream closes and no more chunks are available, this returns
Ok(None)
. - If the stream encounters an
error
, this returnsErr(error)
.
Sourcepub fn release_lock(self)
pub fn release_lock(self)
Releases this reader’s lock on the corresponding stream.
Panics if the reader still has a pending read request, i.e. if a future returned
by read
is not yet ready. For a non-panicking variant,
use try_release_lock
.
Sourcepub fn try_release_lock(self) -> Result<(), (Error, Self)>
pub fn try_release_lock(self) -> Result<(), (Error, Self)>
Sourcepub fn into_stream(self) -> IntoStream<'stream>
pub fn into_stream(self) -> IntoStream<'stream>
Converts this ReadableStreamDefaultReader
into a Stream
.
This is similar to ReadableStream.into_stream
,
except that after the returned Stream
is dropped, the original ReadableStream
is still
usable. This allows reading only a few chunks from the Stream
, while still allowing
another reader to read the remaining chunks later on.