#useTask$ run on parallel for a page?

12 messages · Page 1 of 1 (latest)

tired scroll
#

i will have a page that load many components, independent, every one with useTask$ and a server$ call to load his unique data.
My question is if all useTask$ that will be SSR on the server on a given page will be called in parallel and wait all for a resolution? or one by one in sequence?

vernal trench
little geyser
#

#announcements message

#

that was a design decision

#

otherwise you will very easily have race condition issues

tired scroll
#

sure i made some "test"
`import { component$, useTask$ } from '@builder.io/qwik';
import { server$ } from '@builder.io/qwik-city';

const awaiter = server$(async function(secs: number,name: string) {
console.log(Waiting for ${secs} seconds for ${name});
await new Promise(resolve => setTimeout(resolve, secs * 1000));
return secs;
}
);

export const Timerout = component$(({name, secs}: {name: string, secs: number}) => {
useTask$(async () => {
await awaiter(secs, name);
console.log(Done waiting for ${name});
})
return (
<div>esperando</div>
);
}); `

``

#

<Timerout name="Diego" secs={15} /> <Timerout name="Juan" secs={5} /> <Timerout name="Pablo" secs={10} />

#

RESULTS

#

16:55:59 [vite] page reload src/components/timerout/timerout.tsx Waiting for 15 seconds for Diego Waiting for 5 seconds for Juan Waiting for 10 seconds for Pablo Done waiting for Juan Done waiting for Pablo Done waiting for Diego

#

so YES all the "independent" components run in paralell his own task calls but the page will wait 15 seconds to display (the longest await)

vernal trench