I'm trying to run two async operations that don't rely on each other in parallel but I can't seem to get it working.
const activity = fetchActivity(...)
const progress = fetchProgress(...)
await activity
await progress
When I print the properties of activity
and progress
, they're all undefined.
When I run it like this, the properties show up.
const activity = await fetchActivity(...)
const progress = await fetchProgress(...)
I'm thinking somehow the parallel method await
s aren't awaiting properly as when I log the objects to the console, they eventually show up but directly logging the properties don't work out.
UPDATE:
So apparently I can't answer my own question because it was closed but would first like to thank those that directed me to a right answer, albeit not answering my question.
While the actual solution to my problem is given below, the reason not to use this method is given here: Waiting for more than one concurrent await operation, and I should instead pursue the solution that have been mentioned everywhere already.
ANSWER:
The value of the await
s is not stored in a variable so directly accessing it afterward doesn't work out.
const activity = fetchActivity(...)
const progress = fetchProgress(...)
const activityData = await activity
const progressData = await progress