Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140220

Javascript chaining promise seemingly change execution order

$
0
0

In the following code

let urls = [
  'https://api.github.com/users/iliakan',
];

//let requests = urls.map((url) => axios.get(url).then(() => { console.log('Prout')}));
let requests = urls.map((url) => axios.get(url));
console.log('Start');

axios.get(urls[0])
  .then((responses) => {
    console.log('Got Response');
    return Promise.all(requests);
  }).then((resp) => {
    console.log('Finished Mapping');
  });

The console print out the expected

Start

Got response

Finished Mapping

But if you switch with the commented out definition then I get on the console

Start

Prout

Got response

Finished Mapping

...as if the interpreted reordered the logging of 'Got Response' and the execution of promises in requests.

What is happening here ?


Viewing all articles
Browse latest Browse all 140220


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>