Simulating async await in javascript

Sometimes we may need to simulate async/await locally for testing purposes instead of calling the actual API.

Using "new Promise" with setTimeout

async function simulateAsync() {
  await new Promise(resolve => setTimeout(resolve, 5000));
  return "simulatedAsyncAwait";
}

(async function() {
  var response = await simulateAsync();
  console.log(response);
})();


// 🥳 Results After 5 seconds
// simulatedAsyncAwait