0
0
Node.jsframework~10 mins

Sequential vs parallel async execution in Node.js - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to run two async functions one after another (sequentially).

Node.js
async function runSequential() {
  await fetchData1();
  await [1]();
}
Drag options to blanks, or click blank then click option'
AfetchData2
BfetchData3
CfetchData1
DfetchData4
Attempts:
3 left
💡 Hint
Common Mistakes
Calling both functions without await causes parallel execution.
Forgetting to await the second function.
2fill in blank
medium

Complete the code to run two async functions in parallel and wait for both to finish.

Node.js
async function runParallel() {
  await Promise.[1]([fetchData1(), fetchData2()]);
}
Drag options to blanks, or click blank then click option'
Aany
BallSettled
Crace
Dall
Attempts:
3 left
💡 Hint
Common Mistakes
Using Promise.race waits only for the first promise to settle.
Using Promise.any waits for the first fulfilled promise, not all.
3fill in blank
hard

Fix the error in the code to correctly run async functions sequentially.

Node.js
async function run() {
  await fetchData1();
  [1] fetchData2();
}
Drag options to blanks, or click blank then click option'
Athen
Basync
Cawait
Dreturn
Attempts:
3 left
💡 Hint
Common Mistakes
Calling async functions without await runs them in parallel.
Using async keyword incorrectly inside the function body.
4fill in blank
hard

Fill both blanks to create a parallel async execution that handles errors gracefully.

Node.js
async function runSafeParallel() {
  const results = await Promise.[1]([
    fetchData1(),
    fetchData2()
  ]);
  results.forEach(result => {
    if (result.status === '[2]') {
      console.log('Success:', result.value);
    } else {
      console.error('Error:', result.reason);
    }
  });
}
Drag options to blanks, or click blank then click option'
AallSettled
Bfulfilled
Crejected
Dresolved
Attempts:
3 left
💡 Hint
Common Mistakes
Using Promise.all rejects immediately on any error.
Checking for status 'resolved' instead of 'fulfilled'.
5fill in blank
hard

Fill all three blanks to create a dictionary of results from parallel async calls filtering only successful ones.

Node.js
async function getResults() {
  const results = await Promise.[1]([
    fetchData1(),
    fetchData2(),
    fetchData3()
  ]);
  return results.reduce((acc, [2], index) => {
    if ([3].status === 'fulfilled') {
      acc[`data${index + 1}`] = [2].value;
    }
    return acc;
  }, {});
}
Drag options to blanks, or click blank then click option'
AallSettled
Bresult
Cresults
Dres
Attempts:
3 left
💡 Hint
Common Mistakes
Using Promise.all which rejects on first error.
Using wrong variable names causing runtime errors.