pub struct StreamingSession { /* private fields */ }Expand description
A progressive HTML response driven one chunk at a time from Node.
Every method returns the bytes it produced. Write them to the response and
await drain whenever write() returns false; the session holds no
transport and never blocks on one.
const session = protocol.streamResponse('index.html', '/');
const weather = session.boundary('weather-shell');
res.write(session.writeShell(shellState));
res.write(session.writeBoundary(weather, weatherState, 'updatable'));
res.write(session.update(weather, forecast));
res.end(session.finish(tailState));Implementations§
Source§impl StreamingSession
impl StreamingSession
Sourcepub fn boundary(&self, name: String) -> Result<u32>
pub fn boundary(&self, name: String) -> Result<u32>
Resolve an authored boundary name to a stable integer handle.
Resolve once outside the write loop; the handle costs nothing to reuse.
Sourcepub fn boundary_count(&self) -> u32
pub fn boundary_count(&self) -> u32
Number of compile-time boundaries declared by this entry.
Sourcepub fn write_shell(&mut self, state_json: String) -> Result<Buffer>
pub fn write_shell(&mut self, state_json: String) -> Result<Buffer>
Render everything before the first boundary.
Sourcepub fn write_boundary(
&mut self,
boundary: u32,
state_json: String,
mode: Option<String>,
) -> Result<Buffer>
pub fn write_boundary( &mut self, boundary: u32, state_json: String, mode: Option<String>, ) -> Result<Buffer>
Render and commit the next boundary in declaration order.
mode is "final" (default) or "updatable". Only updatable
boundaries accept later update() calls.
Trait Implementations§
Source§impl FromNapiMutRef for StreamingSession
impl FromNapiMutRef for StreamingSession
Source§unsafe fn from_napi_mut_ref(
env: napi_env,
napi_val: napi_value,
) -> Result<&'static mut Self>
unsafe fn from_napi_mut_ref( env: napi_env, napi_val: napi_value, ) -> Result<&'static mut Self>
This function called to convert napi values to native rust values Read more
Source§impl FromNapiRef for StreamingSession
impl FromNapiRef for StreamingSession
Source§unsafe fn from_napi_ref(
env: napi_env,
napi_val: napi_value,
) -> Result<&'static Self>
unsafe fn from_napi_ref( env: napi_env, napi_val: napi_value, ) -> Result<&'static Self>
This function called to convert napi values to native rust values Read more
Source§impl JavaScriptClassExt for StreamingSession
impl JavaScriptClassExt for StreamingSession
fn into_instance<'scope>( self, env: &'scope Env, ) -> Result<ClassInstance<'scope, Self>>
fn into_reference(self, env: Env) -> Result<Reference<Self>>
fn instance_of<'env, V: JsValue<'env>>(env: &Env, value: &V) -> Result<bool>
Source§impl ObjectFinalize for StreamingSession
impl ObjectFinalize for StreamingSession
Source§impl ToNapiValue for StreamingSession
impl ToNapiValue for StreamingSession
Source§unsafe fn to_napi_value(
env: napi_env,
val: StreamingSession,
) -> Result<napi_value>
unsafe fn to_napi_value( env: napi_env, val: StreamingSession, ) -> Result<napi_value>
This function called to convert rust values to napi values Read more
fn into_unknown(self, env: &Env) -> Result<Unknown<'_>, Error>
Source§impl TypeName for StreamingSession
impl TypeName for StreamingSession
Source§impl TypeName for &StreamingSession
impl TypeName for &StreamingSession
Source§impl TypeName for &mut StreamingSession
impl TypeName for &mut StreamingSession
Source§impl ValidateNapiValue for &StreamingSession
impl ValidateNapiValue for &StreamingSession
Source§unsafe fn validate(env: napi_env, napi_val: napi_value) -> Result<napi_value>
unsafe fn validate(env: napi_env, napi_val: napi_value) -> Result<napi_value>
This function called to validate whether napi value passed to rust is valid type. Read more
Source§impl ValidateNapiValue for &mut StreamingSession
impl ValidateNapiValue for &mut StreamingSession
Source§unsafe fn validate(env: napi_env, napi_val: napi_value) -> Result<napi_value>
unsafe fn validate(env: napi_env, napi_val: napi_value) -> Result<napi_value>
This function called to validate whether napi value passed to rust is valid type. Read more
Auto Trait Implementations§
impl !RefUnwindSafe for StreamingSession
impl !Send for StreamingSession
impl !Sync for StreamingSession
impl !UnwindSafe for StreamingSession
impl Freeze for StreamingSession
impl Unpin for StreamingSession
impl UnsafeUnpin for StreamingSession
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
Mutably borrows from an owned value. Read more
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>
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 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>
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