component::bindgen: Impossible to call async functions on host in imported async functions
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 12/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- rust, wasm
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Rust
- Star
- 18.9k
- Fork
- 2k
- Merge trung bình
- 1 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 238
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của bytecodealliance/wasmtime
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
bytecodealliance/wasmtime#15536 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
bytecodealliance/wasmtime#15455 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
wasi-preview1-component-adapter: fd_write does not invalidate cached InputStream, causing stale readsCó thể đã có người làm @dpfens đã nhận 13 ngày trước. Đang mởwasi
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
bytecodealliance/wasmtime#15296 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug wasm-proposal:exceptions wasmtime:debugging
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
bytecodealliance/wasmtime#14102 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
wasm-proposal:gc
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
bytecodealliance/wasmtime#13808 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của bytecodealliance/wasmtime
Issue tương tự
-
Android: a long press's `contextmenu` event carries no point (`clientX` and `clientY` are 0)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Test connection's password prompt says the password is never saved, also for a keychain profileĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area: settings bug Haiku review: no-score ui
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
MMFoundation/WallpaperMachine#346 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
rubys/roundhouse#2473 ·
-
bug mod: quantum info
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Qiskit/qiskit#17699 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày