Trait stateroom_wasm::StateroomContext
source · pub trait StateroomContext: Send + Sync + 'static {
// Required methods
fn send_message(
&self,
recipient: impl Into<MessageRecipient>,
message: impl Into<MessagePayload>
);
fn set_timer(&self, ms_delay: u32);
}
Expand description
Provides an interface for a StateroomService instance to send messages back to its host environment.
Required Methods§
sourcefn send_message(
&self,
recipient: impl Into<MessageRecipient>,
message: impl Into<MessagePayload>
)
fn send_message( &self, recipient: impl Into<MessageRecipient>, message: impl Into<MessagePayload> )
Sends a message to a currently connected user, or broadcast a message to all users.
Recipient can be a u32
representing an individual user to send a message to, or
MessageRecipient::Broadcast
to broadcast a message to all connected users.
The message is a string which is sent verbatim to the user(s) indicated.
sourcefn set_timer(&self, ms_delay: u32)
fn set_timer(&self, ms_delay: u32)
Sets a timer to wake up the service in the given number of milliseconds by invoking timer()
.
Each instance of a service can only have one (or zero) timer outstanding at any time; if this is called before an existing timer expires, the previous timer is replaced. This provides a very basic primitive that more complex timer behavior can be built on, using state and logic stored in your service. For example, you could implement multiple concurrent timers using a priority queue and ensuring that the environment timer always reflects the head of the queue.