mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-02-06 13:17:02 +00:00
refactor: dynamic dispatch async commands in debug (#13464)
* Dynamic dispatch async commands * format * Preserve `'static` * Use a inner function instead * Only do it for dev for now * Add change file * Tag respond_async_serialized_dyn with debug
This commit is contained in:
parent
a35600cbd7
commit
6a39f49991
5
.changes/dynamic-dispatch-async-commands.md
Normal file
5
.changes/dynamic-dispatch-async-commands.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
tauri: "patch:perf"
|
||||
---
|
||||
|
||||
Use dynamic dispatch for async commands in dev, this should speed up the compilation time by quite a bit, and significantly reduces the incremental compilation time
|
||||
@ -339,6 +339,34 @@ impl<R: Runtime> InvokeResolver<R> {
|
||||
|
||||
/// Reply to the invoke promise with an async task which is already serialized.
|
||||
pub fn respond_async_serialized<F>(self, task: F)
|
||||
where
|
||||
F: Future<Output = Result<InvokeResponseBody, InvokeError>> + Send + 'static,
|
||||
{
|
||||
// Dynamic dispatch the call in dev for a faster compile time
|
||||
// TODO: Revisit this and see if we can do this for the release build as well if the performace hit is not a problem
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
self.respond_async_serialized_dyn(Box::pin(task))
|
||||
}
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
self.respond_async_serialized_inner(task)
|
||||
}
|
||||
}
|
||||
|
||||
/// Dynamic dispatch the [`Self::respond_async_serialized`] call
|
||||
#[cfg(debug_assertions)]
|
||||
fn respond_async_serialized_dyn(
|
||||
self,
|
||||
task: std::pin::Pin<
|
||||
Box<dyn Future<Output = Result<InvokeResponseBody, InvokeError>> + Send + 'static>,
|
||||
>,
|
||||
) {
|
||||
self.respond_async_serialized_inner(task)
|
||||
}
|
||||
|
||||
/// Reply to the invoke promise with an async task which is already serialized.
|
||||
fn respond_async_serialized_inner<F>(self, task: F)
|
||||
where
|
||||
F: Future<Output = Result<InvokeResponseBody, InvokeError>> + Send + 'static,
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user