pub struct Runtime { /* private fields */ }Expand description
Compiled WASM runtime. Thread-safe, can be shared across threads via Arc. Compiles WASM once, then each controller gets its own isolated Store/Instance. Holds a pool of initialized controllers for reuse across invocations.
Implementations§
Source§impl Runtime
impl Runtime
Sourcepub fn new(
_: SurrealismPackage,
server_pool_size: usize,
server_max_memory: Option<usize>,
server_max_execution_time: Option<Duration>,
server_max_kv_entries: Option<usize>,
server_max_kv_value_bytes: Option<usize>,
) -> SurrealismResult<Self>
pub fn new( _: SurrealismPackage, server_pool_size: usize, server_max_memory: Option<usize>, server_max_execution_time: Option<Duration>, server_max_kv_entries: Option<usize>, server_max_kv_value_bytes: Option<usize>, ) -> SurrealismResult<Self>
Compile the WASM and prepare the runtime.
This is expensive — do it once and share via Arc<Runtime>.
server_pool_size, server_max_memory, server_max_execution_time,
server_max_kv_entries, and server_max_kv_value_bytes are the
server-level ceilings from environment variables.
Sourcepub fn kv_store(&self) -> &Arc<BTreeMapStore> ⓘ
pub fn kv_store(&self) -> &Arc<BTreeMapStore> ⓘ
Returns the per-module KV store. This store is shared across all invocations and persists for the lifetime of the Runtime.
Sourcepub fn config(&self) -> &SurrealismConfig
pub fn config(&self) -> &SurrealismConfig
Returns the module configuration.
Sourcepub fn resolved_allow_net(&self) -> Arc<Vec<ResolvedNetAllow>> ⓘ
pub fn resolved_allow_net(&self) -> Arc<Vec<ResolvedNetAllow>> ⓘ
Resolved allow_net from module load (same snapshot used for WASI socket filtering).
Sourcepub async fn acquire_controller(
&self,
context: Box<dyn InvocationContext>,
) -> SurrealismResult<Controller>
pub async fn acquire_controller( &self, context: Box<dyn InvocationContext>, ) -> SurrealismResult<Controller>
Acquire a controller ready for invocation. Reuses a pooled controller if available
(preserving WASM memory / statics from prior runs), otherwise creates and initializes
a fresh one — waiting on Semaphore if max_pool_size controllers are already checked
out. The supplied context is installed before returning.
The semaphore permit is acquired before checking the pool so that a popped controller is never outstanding without a matching permit.
Sourcepub fn release_controller(&self, controller: Controller)
pub fn release_controller(&self, controller: Controller)
Return a controller to the pool for reuse. The invocation context is cleared (replaced with a NullContext) so no per-request state is retained on the host side. WASM linear memory (statics, heap) is preserved for the next invocation.
Do NOT release a controller after a WASM trap — drop it instead to discard potentially inconsistent instance state.
Sourcepub fn get_signature(
&self,
sub: Option<&str>,
) -> SurrealismResult<&FunctionExport>
pub fn get_signature( &self, sub: Option<&str>, ) -> SurrealismResult<&FunctionExport>
Look up a function signature from the exports manifest.
Sourcepub fn exports(&self) -> &ExportsManifest
pub fn exports(&self) -> &ExportsManifest
Access the full exports manifest.
Sourcepub async fn new_controller(
&self,
context: Box<dyn InvocationContext>,
) -> SurrealismResult<Controller>
pub async fn new_controller( &self, context: Box<dyn InvocationContext>, ) -> SurrealismResult<Controller>
Create a new Controller with its own isolated Store and Instance.
Import resolution is already done (in InstancePre); this only allocates
memory, initializes state, and runs any start functions.
Prefer acquire_controller for the reuse path. This is the low-level constructor.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Runtime
impl !RefUnwindSafe for Runtime
impl Send for Runtime
impl Sync for Runtime
impl Unpin for Runtime
impl UnsafeUnpin for Runtime
impl !UnwindSafe for Runtime
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
Source§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
Source§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
self file descriptor.Source§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
Source§fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
self file descriptor. Read moreSource§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
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>
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