pub struct HmrBroadcaster { /* private fields */ }Expand description
Fan-out HMR sender shared across the dev server.
Construct one per ssg dev process. Each connected tab registers
an HmrSink via Self::subscribe; Self::broadcast pushes
the same frame to every live tab and evicts any sink that errored.
Implementations§
Source§impl HmrBroadcaster
impl HmrBroadcaster
Sourcepub fn new() -> Self
pub fn new() -> Self
Construct an empty broadcaster.
§Examples
use ssg::hmr::HmrBroadcaster;
let b = HmrBroadcaster::new();
assert_eq!(b.subscriber_count(), 0);Sourcepub fn subscribe(&self, sink: HmrSink)
pub fn subscribe(&self, sink: HmrSink)
Register a new tab. The sink is invoked on every subsequent
Self::broadcast until it returns Err(()).
§Examples
use ssg::hmr::HmrBroadcaster;
let b = HmrBroadcaster::new();
b.subscribe(Box::new(|_| Ok(())));
assert_eq!(b.subscriber_count(), 1);Sourcepub fn subscriber_count(&self) -> usize
pub fn subscriber_count(&self) -> usize
Returns the current number of subscribed tabs. Useful for tests and the dev-server status banner.
§Examples
use ssg::hmr::HmrBroadcaster;
let b = HmrBroadcaster::new();
assert_eq!(b.subscriber_count(), 0);Sourcepub fn broadcast(&self, msg: &HmrMessage) -> usize
pub fn broadcast(&self, msg: &HmrMessage) -> usize
Push msg to every subscriber. Sinks that return Err(()) are
evicted in-place.
Returns the number of tabs that successfully received the frame.
§Examples
use ssg::hmr::{HmrBroadcaster, HmrMessage};
let b = HmrBroadcaster::new();
b.subscribe(Box::new(|_| Ok(())));
assert_eq!(b.broadcast(&HmrMessage::reload()), 1);Trait Implementations§
Source§impl Debug for HmrBroadcaster
impl Debug for HmrBroadcaster
Source§impl Default for HmrBroadcaster
impl Default for HmrBroadcaster
Source§fn default() -> HmrBroadcaster
fn default() -> HmrBroadcaster
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !Freeze for HmrBroadcaster
impl RefUnwindSafe for HmrBroadcaster
impl Send for HmrBroadcaster
impl Sync for HmrBroadcaster
impl Unpin for HmrBroadcaster
impl UnsafeUnpin for HmrBroadcaster
impl UnwindSafe for HmrBroadcaster
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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