Is there any way to call the backend without freezing the web window? #4191
-
Hi, First of all, Thanks you so much for the Tauri team. This code really is a game changer ! I am using Tauri to load some images from rust. My front end code looks something like this: function startCaching(){
for (let nFrame=0; nFrame<9; nFrame++){
imageNumber = 1 + nFrame;
invoke('get_image_raw_data', { imageNumber, canvasW, canvasH }).then((data_from_rust) => {
rawImagesFrames.push(data_from_rust);
})
}
} And my backend code looks something like this: #[tauri::command]
fn get_image_raw_data(image_number: i32, canvas_w: f32, canvas_h: f32) -> Result<Vec<u8>, String> {
use image::GenericImageView;
...
// Return raw image
Ok(img_raw_data) The problem is that when I call P.S: I found this issue that might be the same problem I am having. If this is actually a bug, is there any workaround while I white for the tauri team to solve it? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 12 replies
-
Make the command async, either by changing it to |
Beta Was this translation helpful? Give feedback.
Make the command async, either by changing it to
async fn
or#[tauri::command(async)]
. This way it doesn't run on the main thread.