Crates.io | wapc-pool |
lib.rs | wapc-pool |
version | 1.1.0 |
source | src |
created_at | 2022-01-24 18:33:06.671193 |
updated_at | 2023-03-23 14:34:15.769989 |
description | A multithreaded pool of waPC hosts |
homepage | https://wapc.io |
repository | |
max_upload_size | |
id | 520342 |
size | 54,068 |
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;
#[tokio::main]
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()
})
.max_threads(5)
.build();
let bytes = pool.call("echo", serialize("Hello!")?).await?;
let result: String = deserialize(&bytes)?;
println!("Wasm module returned: {}", result);
Ok(())
}