pub struct StreamingSession { /* private fields */ }Expand description
A progressive HTML response driven one semantic step at a time from Node.
start(), resume(), and advance() return bytes, completion state, and
the next runtime boundary occurrence (if any). Boundary keys retain their
authored JSON type: strings are JavaScript strings and finite numbers are
JavaScript numbers.
const session = protocol.streamResponse('index.html', '/');
let step = session.start(JSON.stringify(shellState));
res.write(step.bytes);
while (!step.done) {
const { instanceId, name, key } = step.boundary;
const state = await loadBoundary(name, key);
step = session.resume(instanceId, JSON.stringify(state), 'updatable');
res.write(step.bytes);
step = session.advance();
res.write(step.bytes);
}Implementations§
Source§impl StreamingSession
impl StreamingSession
Sourcepub fn start(&mut self, state_json: String) -> Result<JsStreamStep>
pub fn start(&mut self, state_json: String) -> Result<JsStreamStep>
Render until the first runtime boundary occurrence or terminal.
Sourcepub fn resume(
&mut self,
instance_id: u32,
state_json: String,
mode: Option<String>,
) -> Result<JsStreamStep>
pub fn resume( &mut self, instance_id: u32, state_json: String, mode: Option<String>, ) -> Result<JsStreamStep>
Commit the pending occurrence through its checkpoint, then stop.
mode is "final" (default) or "updatable". Only updatable
boundaries accept later update() calls.
Sourcepub fn advance(&mut self) -> Result<JsStreamStep>
pub fn advance(&mut self) -> Result<JsStreamStep>
Write the parent bytes after the committed occurrence.
Valid only after resume(). Returns the next boundary occurrence or
completes the document tail.
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 TypeTag for StreamingSession
impl TypeTag for StreamingSession
Source§fn type_tag() -> napi_type_tag
fn type_tag() -> napi_type_tag
Returns this class’s stable per-type tag. The derive computes it from the
class’s content identity string (
crate@version::module_path::ClassName),
which is fixed for a given class, so repeated calls return the same tag.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 !Sync for StreamingSession
impl !UnwindSafe for StreamingSession
impl Freeze for StreamingSession
impl Send 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