Asynchronous JavaScript to fetch remote JSON data with promises and generators
Why do not use async / await functions? Its just syntactic sugar for promises / generators. Check this vanilla JS snippet, is live:



var url1 = 'https://jsonplaceholder.typicode.com/posts/2'
var url2 = 'https://jsonplaceholder.typicode.com/posts/3'

async function mimicSyncInside () {
  console.log('Before')
  console.log(await fetch(url1).then(resp =&gt; resp.json()))
  console.log(await fetch(url2).then(resp =&gt; resp.json()))
  console.log('After')
}

mimicSyncInside()