hnasr / javascript_playground

Javascript playground tutorials
1.06k stars 948 forks source link

Display results as soon as they come in #21

Closed Luukth closed 3 years ago

Luukth commented 3 years ago

I implemented the suggestion from Viraj Singh:

I would fix your problem at 8:20 by doing something like:

Promise.all( ['0-10', '10-20', '30-40' ].map(fetchAndUpdateGrades))

async function fetchAndUpdateGrades( grade ) {

// fetching data for a given grade const result = await fetch('localhost:8000/'+grade);

// updating UI as soon as I get data back from server for this grade document.getElementById(grade).innerText = result.data;

} https://www.youtube.com/watch?v=eI_EQNTxF6U

The results will now display as soon as they come in. When all the results are in the duration will be displayed/calculated.

hnasr commented 3 years ago

Good fix! Thanks Luukth and Viraj Singh for the fix!