Skip to content

Instantly share code, notes, and snippets.

@jessamynsmith
Created November 8, 2018 21:46
Show Gist options
  • Save jessamynsmith/bb29c42ce855597cb55f70f8114c64aa to your computer and use it in GitHub Desktop.
Save jessamynsmith/bb29c42ce855597cb55f70f8114c64aa to your computer and use it in GitHub Desktop.
function myAsyncFunction(url) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.onload = () => resolve(xhr.responseText);
xhr.onerror = () => reject(xhr.statusText);
xhr.send();
});
}
prom = myAsyncFunction('https://www.google.com');
prom.then(function(res) {console.log(res)});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment