CPP: async guest bindings sketch
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
- 30/100
Hướng nghiên cứu
Không có tệp hoặc bài kiểm thử nào được nêu. Hãy bắt đầu bằng cách so sánh cách tiếp cận async C bindgen hiện có với khả năng hỗ trợ C++17 hiện tại, sau đó đánh giá các lựa chọn được đề xuất về coroutine C++20, quyền sở hữu, hủy và lỗi. Để được xem là hoàn tất, cần có một thiết kế được maintainer phê duyệt và một phiên bản C++ tối thiểu đã được thống nhất; phạm vi triển khai chưa được xác định.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
While we could go with exactly the choices made for async c bindgen, I'd like to sketch a C++ native solution.
C++20 introduces coroutines which are a much closer fit to the co-operative threads design in the component model.
The perennial challenge with C++ is which minimum version should we support? I see where we lean into C++ 17 features today, but could/should we raise the bar to C++20? I started sketching what it might look like assuming we could depend on C++20 and also assuming we wouldn't go to C++23.
cc @cpetig
Some basic design decisions:
- Should we use exceptions for async failures? These appear to be uncommon in modern C++ for perf reasons and we should use
std::expected<T, AsyncError>instead. - Move semantics for all async operations, and have them only use owned values (to prevent use-after-move)
- No references/borrows in async contexts (to prevent dangling)
- All operations are cancellable
- RAII for automatic handle cleanup
Just a heads up that I'm knocking some rust off (pun intended) after having not written C++ professionally in several years. So please don't take my proposal here as authoritative as there's a solid chance I've missed some features we may want to take advantage of.
Usage example
interface example {
get-value: async func() -> u32;
}
// Bindings
namespace example {
// Async import
Task<uint32_t> GetValue();
// Implementation (export)
namespace exports {
uint32_t GetValue() {
// User implementation
return 42;
}
}
}
// Usage
Task<uint32_t> example_task = example::GetValue();
uint32_t value = co_await example_task;
Sketches on implementation details
// Cancellation support
auto cancel() -> std::optional<T> {
uint32_t status = writer_->vtable_->cancel_write(writer_->handle_);
if (status == (uint32_t)AsyncStatus::Cancelled) {
// Successfully cancelled, return original value
return std::move(value_);
}
return std::nullopt; // Already completed
}
Sketch for reading values from a stream:
// Read one value (returns nullopt on EOF)
auto next() -> Task<std::optional<T>> {
T value;
auto result = co_await read(std::span<T>(&value, 1));
if (result.count == 0) {
co_return std::nullopt;
}
co_return std::move(value);
}
// Collect all remaining values
auto collect() -> Task<std::vector<T>> {
std::vector<T> results;
while (auto val = co_await next()) {
results.push_back(std::move(*val));
}
co_return results;
}
- Ngôn ngữ chính
- Rust
- Star
- 1.5k
- Fork
- 306
- Merge trung bình
- 1 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 21
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Không 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/wit-bindgen
-
gen-rust
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
bytecodealliance/wit-bindgen#1791 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
gen-rust
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
bytecodealliance/wit-bindgen#1790 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Document build.rs approachĐang mởgen-rust
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 55/100
bytecodealliance/wit-bindgen#1787 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
gen-c#
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
bytecodealliance/wit-bindgen#1759 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Async exports never free the block of indirect parametersCó thể đã có người làm @Aditya1404Sal đã nhận 37 ngày trước. Đang mởasync
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
bytecodealliance/wit-bindgen#1757 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của bytecodealliance/wit-bindgen
Issue tương tự
-
lane:collections todo:ticket
Độ 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
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 3 ngày
-
bugfix
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
storytold/designcraft#3662 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue tooling
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Nixitov/Riptide-Native#521 ·
Maintainer thường phản hồi trong vòng 1 ngày