Skip to content

Instantly share code, notes, and snippets.

@treyhuffine
Last active June 22, 2020 17:26
Show Gist options
  • Save treyhuffine/4fdf8a0baf9e1de209b0eb96031780d4 to your computer and use it in GitHub Desktop.
Save treyhuffine/4fdf8a0baf9e1de209b0eb96031780d4 to your computer and use it in GitHub Desktop.
const apiRequest = () => {
return new Promise((resove) => {
// do some async things for an unknown amount of time...
return resolve({ answer: 42 });
})
}
const run = () => {
apiRequest.then((response) => {
console.log(response);
})
}
// Since it's all just promises, you can mix and match with async/await
const runAsAsyncAwait = async () => {
const response = await apiRequest();
console.log(response);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment