Crate wapc_pool

source ·
Expand description

waPC Pool license

This crate implements a multi-threaded pool of waPC hosts. You’ll typically use the HostPoolBuilder to create a HostPool and use .call() to initiate requests as you would on a standard WapcHost.

The HostPool has basic elasticity built in. Specify the minimum number of threads to start with and the maximum number to grow to. Give the pool a max_wait duration before starting a new worker and a max_idle duration to auto-kill workers above the minimum size.

use std::fs::read;

use wapc::WapcHost;
use wapc_codec::messagepack::{deserialize, serialize};
use wapc_pool::HostPoolBuilder;

async fn main() -> anyhow::Result<()> {
  let file = read("../../wasm/crates/wapc-guest-test/build/wapc_guest_test.wasm")?;

  let engine = wasmtime_provider::WasmtimeEngineProvider::new(&file, None)?;

  let pool = HostPoolBuilder::new()
    .name("pool example")
    .factory(move || {
      let engine = engine.clone();
      WapcHost::new(Box::new(engine), None).unwrap()

  let bytes ="echo", serialize("Hello!")?).await?;

  let result: String = deserialize(&bytes)?;

  println!("Wasm module returned: {}", result);



  • Library-specific error types and utility functions