2

I want to know if it is possible to run invoke from Tauri, in a web worker. I am using Tauri and Svelte. When I try to use invoke from a web worker, I get this error:

chunk-NMUKSDLG.js:1 Uncaught ReferenceError: window is not defined at chunk-NMUKSDLG.js:1:11157

I know that window isn't available in web workers, but is there another API that I can use, other than invoke?

Note, see comment.

Fighter178
  • 303
  • 2
  • 9
  • The reason I'm trying this is because I have a very expensive operation that is done on the backend. I have tried spinning up a new thread, but that didn't seem to make it better. I still hung the frontend Tauri app. So, I guess what I'm really asking is if there is a way to call a backend function truly concurrently? – Fighter178 Aug 05 '23 at 08:19
  • Hi, you could use Tauri async commands : [here](https://tauri.app/v1/guides/features/command/#async-commands) it would be spawn on another thread than the main one. From Javascript side you can still normally await for the response. As per the docs, the command return type should be wrapped in a Result<> – Loulou BadWeed Sep 02 '23 at 01:20

0 Answers0