component::bindgen: Impossible to call async functions on host in imported async functions
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 12/100
- Tipo de issue
- Error
- Claridad
- Necesita aclaración
- Estado de actividad
- Activo
- Stack tecnológico
- rust, wasm
- Área
- backend-api-design
Línea de trabajo
The question centres on the bindgen! macro's imports block with async | trappable and the HostWithStore impl for HasSelf<PluginHost>, where evaluate_expression2 receives an &Accessor<T, Self>. Start with the Accessor::with and Accessor::spawn methods, and with the _7_async bindgen example the issue links to. Done would mean either a supported way for an async host function to await async host work, or a documented answer to that question. The issue is unresolved and needs a maintainer decision on the API first.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
component::bindgen! supports async for imported functions in two ways. First, in that it allows async implementations for any Wasm function. Second, in that it supports implementations of async Wasm functions.
I'm having a hard time with the latter because it requires the use of a WithStore interface, which in turn allows access to the host object via an Accessor. The Accessor deliberately only allows blocking access to the host, but I need async access to it. Ironically, perhaps, this is not a problem with blocking Wasm functions. But from what I can tell, it is simply impossible with async Wasm functions.
Here's an example.
From the WIT file:
...
interface host {
evaluate-expression1: func(expression: string) -> result<option<string> string>;
evaluate-expression2: async func(expression: string) -> result<option<string>, string>;
}
Generating the bindings:
wasmtime::component::bindgen!({
...
imports: {
"test:plugins/host.evaluate-expression1": async | trappable,
"test:plugins/host.evaluate-expression2": async | trappable,
}
});
Implementation:
impl imported::Host for PluginHost
{
async fn evaluate_expression1(
&mut self,
expression: String,
) -> wasmtime::Result<Result<Option<String>, String>> {
// No problem calling an async function on self here!
Ok(self.evaluate_expression_impl(expression).await)
}
}
impl imported::HostWithStore<T> for HasSelf<PluginHost>
{
async fn evaluate_expression2(
accessor: &Accessor<T, Self>,
expression: imported::String,
) -> wasmtime::Result<Result<Option<String>, String>> {
// How do I call evaluate_expression_impl here???
todo!()
}
}
I'm stuck. Accessor::with only supports blocking code and Accessor::spawn doesn't change that. The example code doesn't help, because it only shows blocking code. (I'm confused about this example. What is the use case for a blocking implementation of an async Wasm function?)
I think I understand the technical limitation. Imported async Wasm functions are being "driven" by the async implementation of the component, which the implementation does not control.
What can I do? Is this really impossible? My use case seems like it would be quite common. It seems to me that there should be a way to "hand over" my host async function to the component's async implementation to "drive". Or maybe I'm misunderstanding the situation entirely. :)
I would humbly suggest that if there is a solution, it should be shown in the example I linked above.
- Lenguaje dominante
- Rust
- Estrellas
- 18.9k
- Forks
- 2k
- Merge medio
- 1 d 6 h
- PR fusionados (30 d)
- 238
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de bytecodealliance/wasmtime
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
bytecodealliance/wasmtime#15536 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
bytecodealliance/wasmtime#15455 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
wasi-preview1-component-adapter: fd_write does not invalidate cached InputStream, causing stale readsPosiblemente ocupada @dpfens la tomó hace 13 días. Abiertowasi
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
bytecodealliance/wasmtime#15296 ·
Los mantenedores suelen responder en 1 día
-
bug wasm-proposal:exceptions wasmtime:debugging
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
bytecodealliance/wasmtime#14102 ·
Los mantenedores suelen responder en 1 día
-
wasm-proposal:gc
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
bytecodealliance/wasmtime#13808 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de bytecodealliance/wasmtime
Issues similares
-
Android: a long press's `contextmenu` event carries no point (`clientX` and `clientY` are 0)Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Test connection's password prompt says the password is never saved, also for a keychain profileAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
area: settings bug Haiku review: no-score ui
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
MMFoundation/WallpaperMachine#346 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
rubys/roundhouse#2473 ·
-
bug mod: quantum info
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Qiskit/qiskit#17699 · 2 comentarios ·
Los mantenedores suelen responder en 1 día