feat(runtime): add resident Wasmtime actor runtime
- define versioned service and clock WIT contracts - enforce import allowlists, fuel, epoch, memory, I/O, and mailbox limits - keep one Store and Component Instance resident per serial Actor - add echo, counter, fault, spin, and capability probe components - cover lifecycle, concurrency, sandbox, and fault recovery behavior
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
use core::sync::atomic::{AtomicU64, Ordering};
|
||||
|
||||
mod bindings {
|
||||
wit_bindgen::generate!({
|
||||
path: "wit",
|
||||
world: "counter-component",
|
||||
});
|
||||
}
|
||||
|
||||
static COUNTER: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
struct Counter;
|
||||
|
||||
impl bindings::Guest for Counter {
|
||||
fn init(_config: Vec<u8>) -> Result<(), bindings::ServiceError> {
|
||||
// Calls are serialized by the host Actor, so this component intentionally
|
||||
// uses one mutable global to make resident memory observable in tests.
|
||||
COUNTER.store(0, Ordering::Relaxed);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn invoke(_input: Vec<u8>) -> Result<Vec<u8>, bindings::ServiceError> {
|
||||
let next = COUNTER.fetch_add(1, Ordering::Relaxed).wrapping_add(1);
|
||||
Ok(next.to_le_bytes().to_vec())
|
||||
}
|
||||
}
|
||||
|
||||
bindings::export!(Counter with_types_in bindings);
|
||||
Reference in New Issue
Block a user