#useTask$ run on parallel for a page?
12 messages · Page 1 of 1 (latest)
can you share some code of it? it could be down to whether you do await Promise.allSettled or await each server$ call individually
Tasks do not run in parallel, in fact misko speaks about that in-depth in the last office hours session
#announcements message
that was a design decision
otherwise you will very easily have race condition issues
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)
yes the component will be run parallel, but the usetask inside of a component will be sequential, I think this is what Jack meant