Skip to main content

StreamWebModule

Struct StreamWebModule 

Source
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>

Source§

fn from(val: StreamWebModule) -> Self

Converts to this type from the input type.
Source§

impl ModuleDef for StreamWebModule

Source§

fn declare(declare: &Declarations<'_>) -> Result<()>

Source§

fn evaluate<'js>(ctx: &Ctx<'js>, exports: &Exports<'js>) -> Result<()>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ParallelSend for T
where T: Send,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more