Repository navigation
Add async support - #5
alan-george-lk wants to merge 6 commits into
Conversation
b43f243 to
bad762e
Compare
69dd556 to
f18ea96
Compare
bad762e to
8ca7832
Compare
f18ea96 to
0ed332d
Compare
8ca7832 to
ad3267c
Compare
0ed332d to
433eae1
Compare
100f2ea to
f5cd234
Compare
| @@ -0,0 +1,102 @@ | |||
| #include <test_common.hpp> | |||
There was a problem hiding this comment.
do we need some copyright headers for the new files that we add ?
| promise_.set_value(); | ||
| } | ||
| } else { | ||
| auto value = complete_(handle_, &status); |
There was a problem hiding this comment.
what will happen if the value from complete_(handle_, &status) is valid ?
That says, a race happened, and compete_() is done
| wake_.notify_one(); | ||
| } | ||
|
|
||
| void complete() noexcept { |
There was a problem hiding this comment.
nit, assert(handle_ != nullptr) ?
| } | ||
| } | ||
|
|
||
| free_(handle_); |
There was a problem hiding this comment.
nit, should you set handle_ to nullptr after that ?
| free_(handle_); | ||
| { | ||
| std::lock_guard<std::mutex> lock(mutex_); | ||
| finished_ = true; |
There was a problem hiding this comment.
curiously, do you need finished_ ? can we use handle_, and just check if it is nullptr?
| void start() noexcept { | ||
| try { | ||
| auto state = this->shared_from_this(); | ||
| std::thread([state = std::move(state)]() { |
There was a problem hiding this comment.
this is really worrying, one thread per in-flight future ?
can we do better ?
| template <typename T> | ||
| class Future { | ||
| public: | ||
| Future(std::future<T> future, std::function<void()> cancel): |
There was a problem hiding this comment.
Nit, curiously, from the c++ side, do you think we will need a default constructor, and allow c++ code to assign the future and cancel later ?
I am definitely OK if there is no needs for such things, just want to make sure.
| ) | ||
| {%- endmacro %} | ||
|
|
||
| {% macro rust_call_async_void_with_prefix(prefix, func) -%} |
There was a problem hiding this comment.
These 4 macros look very similar with some small difference like a void return and a optional prefix.
Is there any chance to collapse them into one ? or 2 ?
c396b3b to
2abac60
Compare
f5cd234 to
26bfaa2
Compare
26bfaa2 to
c4ad947
Compare
7d04286 to
8509eb6
Compare
This PR adds initial Rust-to-C++ async support for UniFFI
v0.31.Async functions, constructors, and object methods now return a move-only
uniffi::Future<T>supportingget(),wait(),wait_for(), and cancellation. Dropping an incomplete future also requests cancellation.Poll, cancel, complete, and free operations are serialized on a dedicated worker thread per in-flight future, preventing re-entrant polling and cancellation/completion lifetime races.
Coverage is integrated through the repository’s existing
test_case(futures)convention and includes:voidreturnsAsync callback interfaces, continuation APIs such as
.then(), and a shared/global dispatcher are intentionally out of scope.