Skip to content

Commit

Permalink
Add UniffiCallInvoker::invokeNonBlocking
Browse files Browse the repository at this point in the history
  • Loading branch information
jhugman committed Sep 17, 2024
1 parent 094d817 commit faf0f89
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cpp/includes/UniffiCallInvoker.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,15 @@ class UniffiCallInvoker {
future.wait();
}
}

/**
* Invokes the given function on the JS thread, by adding to
* the event queue.
*/
void invokeNonBlocking(jsi::Runtime &rt, UniffiCallFunc func) {
// react::CallFunc wrapper = [func](jsi::Runtime &rt) {
std::function<void()> wrapper = [func, &rt]() { func(rt); };
callInvoker_->invokeAsync(std::move(wrapper));
}
};
} // namespace uniffi_runtime
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ namespace {{ ns }} {
};
// We'll then call that lambda from the callInvoker which will
// look after calling it on the correct thread.
{% if callback.is_blocking() -%}
callInvoker->invokeBlocking(rt, jsLambda);
{%- else %}
callInvoker->invokeNonBlocking(rt, jsLambda);
{%- endif %}
};
return callback;
}
Expand Down
4 changes: 4 additions & 0 deletions crates/ubrn_bindgen/src/bindings/react_native/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,10 @@ impl FfiCallbackFunction {
.find(|a| a.is_return() && !a.type_().is_void());
arg.map(|a| a.type_())
}

fn is_blocking(&self) -> bool {
self.name() != "RustFutureContinuationCallback"
}
}

fn is_future(nm: &str) -> bool {
Expand Down

0 comments on commit faf0f89

Please sign in to comment.