Run multiple invoke functions in paraller

Hi there,

Is there a way to run multiple invoke functions in parallel?
For example I have:

await invoke("getStorage", {name: "sastConfiguration"}).then(setSastConfiguration);
await invoke("getStorage", {name: "dastConfiguration"}).then(setDastConfiguration);
await invoke("getAssetsByType", {type: 'application'}).then(setSASTAssets);
await invoke("getAssetsByType", {type: 'site'}).then(setDASTAssets);
await invoke("getAllJiraProjects").then(setJiraProjects);
await invoke("getAllJiraUsers").then(setJiraUsers);
await invoke("getAllJiraGroups").then(setJiraGroups);
await invoke("getAllSentinelGroups").then(setSentinelGroups);

which of course take a lot of time. Can i use Promises.all.... or what else would you recommend?

Thank you

Feel free to treat them as a normal Promise request.
Promise.all([invoke, invoke, ...]) will work fine.

Of course keep in mind potential data races and things happening out of order.
Also good practice to consider how to recover if any of the requests fail.

1 Like

any advice how to deal with data races and how to recover from requests fails?
I am not very familiar with JS.

Thank you

You could retry the request as a naive approach.

Other recovery strategies depend on what you’re making.

Guessing by the names these requests are all idempotent GET requests and I’m assuming all the set functions afterwards are modifying things in memory. Retries should be fine in this case assuming the above.