pub struct StreamWebModule;Expand description
Defines web streams, which are exposed through the “stream/web” Node import, but also at the global scope Web streams consist of Readable, Writable, and Transform streams. Transform is currently unimplemented.
https://developer.mozilla.org/en-US/docs/Web/API/Streams_API
§ReadableStream
ReadableStream knows how to ‘pull’ objects or bytes from an underlying source, generally a user-defined function or an [async] iterator. A source enqueues data to the stream via a controller, either ReadableStreamDefaultController or a ReadableByteStreamController optionally for byte data. The controller is created at stream initialisation and cannot change.
Data is read from the stream using a reader, which is obtained using stream.getReader(). A reader ‘locks’ the stream for reading, preventing
other readers from being created. When a reader is released with reader.releaseLock(), the stream goes back to having no reader and a new one can be created.
In the case of ReadableByteStreamController, a special reader ReadableStreamBYOBReader may be used, which allows users to provide their own
buffer to fill bytes into when reading. Otherwise, ReadableStreamDefaultReader is used by default, and this may also be used with byte streams.
A ReadableStream can be ‘tee’d’, which splits it into two readable streams which both read the same underlying data, potentially at different paces. This is an area of substantial complexity for the implementation, particularly in the case of byte streams as the alternative reader types must be handled correctly.
§WritableStream
WritableStream knows how to ‘push’ objects into an underlying sink, generally a user-defined function. It has no special casing for bytes, and so only has one type of controller, WritableStreamDefaultController, and only one type of writer WritableStreamDefaultWriter. The controller is only needed for error handling because writes are signalled via a function call to a user-defined ‘write’ method which receives the chunk directly.
Data is written to the stream using a WritableStreamDefaultWriter, which is obtained using stream.getWriter(). A writer ‘locks’ the stream for writing,
preventing other writers from being created. When a writer is released with writer.releaseLock(), the stream goes back to having no writer and a new one can be created.
Trait Implementations§
Source§impl From<StreamWebModule> for ModuleInfo<StreamWebModule>
impl From<StreamWebModule> for ModuleInfo<StreamWebModule>
Source§fn from(val: StreamWebModule) -> Self
fn from(val: StreamWebModule) -> Self
Auto Trait Implementations§
impl Freeze for StreamWebModule
impl RefUnwindSafe for StreamWebModule
impl Send for StreamWebModule
impl Sync for StreamWebModule
impl Unpin for StreamWebModule
impl UnsafeUnpin for StreamWebModule
impl UnwindSafe for StreamWebModule
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more