Skip to content

Commit

Permalink
feat(rt-wasmtime): reuse Store engine
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Volosatovs <[email protected]>
  • Loading branch information
rvolosatovs committed Jul 8, 2024
1 parent d09db49 commit 6c6f71c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/runtime-wasmtime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wrpc-runtime-wasmtime"
version = "0.17.5"
version = "0.17.6"
description = "wRPC wasmtime integration"

authors.workspace = true
Expand Down
10 changes: 5 additions & 5 deletions crates/runtime-wasmtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,6 @@ pub trait ServeExt: wrpc_transport::Serve {
/// Serve [`types::ComponentItem`]
fn serve_item<T>(
&self,
engine: &Engine,
instance: &Instance,
ty: types::ComponentItem,
store: impl Into<Arc<Mutex<wasmtime::Store<T>>>>,
Expand Down Expand Up @@ -1116,14 +1115,15 @@ pub trait ServeExt: wrpc_transport::Serve {
}
types::ComponentItem::ComponentInstance(ty) => {
let mut instance_store = store.lock().await;
let engine = instance_store.engine().clone();
let mut instance = instance.exports(&mut *instance_store);
let mut instance = instance
.instance(name)
.with_context(|| format!("instance export `{instance_name}` not found"))?;
let instance_name = name;
let mut invocations: SelectAll<Pin<Box<dyn Stream<Item = _> + Send>>> =
SelectAll::new();
for (name, ty) in ty.exports(engine) {
for (name, ty) in ty.exports(&engine) {
match ty {
types::ComponentItem::ComponentFunc(_) => {
debug!(name, "serving instance function export");
Expand Down Expand Up @@ -1170,7 +1170,6 @@ pub trait ServeExt: wrpc_transport::Serve {
/// Serve all exports of this [`InstancePre`]
fn serve_exports<T>(
&self,
engine: &Engine,
instance: InstancePre<T>,
mut store: wasmtime::Store<T>,
) -> impl Future<
Expand All @@ -1180,8 +1179,9 @@ pub trait ServeExt: wrpc_transport::Serve {
T: WasiView + 'static,
{
async move {
let engine = store.engine().clone();
let ty = instance.component().component_type();
let exports = ty.exports(engine);
let exports = ty.exports(&engine);
let instance = instance
.instantiate_async(&mut store)
.await
Expand All @@ -1191,7 +1191,7 @@ pub trait ServeExt: wrpc_transport::Serve {
SelectAll::new();
for (name, ty) in exports {
let s = self
.serve_item(engine, &instance, ty, Arc::clone(&store), "", name)
.serve_item(&instance, ty, Arc::clone(&store), "", name)
.await?;
invocations.push(Box::pin(s));
}
Expand Down

0 comments on commit 6c6f71c

Please sign in to comment.