Skip to content

Instantly share code, notes, and snippets.

@shahab65
Last active December 26, 2019 20:30
Show Gist options
  • Save shahab65/c0d72a278a85b7094d68d9fdd5940d3b to your computer and use it in GitHub Desktop.
Save shahab65/c0d72a278a85b7094d68d9fdd5940d3b to your computer and use it in GitHub Desktop.

If we have multiple promises we could use Promise.all with await

async function asyncFunc() {
  const response = await Promise.all([
    axios.get("/some_url_endpoint"),
    axios.get("/some_url_endpoint")
  ]);
  ...
}

error handling

async function asyncFunc() {
try {
  // fetch data from a url endpoint
  const data = await axios.get("/some_url_endpoint");
  return data;
} catch(error) {
  console.log("error", error);
  // appropriately handle the error
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment