Skip to content

Instantly share code, notes, and snippets.

@MostlyFocusedMike
Created June 10, 2018 22:00
Show Gist options
  • Save MostlyFocusedMike/ca3d00af347ce5c11e8557dec4babe83 to your computer and use it in GitHub Desktop.
Save MostlyFocusedMike/ca3d00af347ce5c11e8557dec4babe83 to your computer and use it in GitHub Desktop.
// we'll use arrow functions for brevity
let asynchProm = new Promise((resolve, reject) => {
let fakeCode = 200;
window.setTimeout(() => {
if (fakeCode === 200) {
resolve({status: "OK"})
} else {
reject({status: "ERROR"})
}
}, 3000);
});
asynchProm
.then((result) => console.log(result.status))
.catch((result) => console.log(result.status))
console.log("Load up your page");
// LOG: Load up your page
** 3 seconds will pass **
// LOG: OK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment