Skip to content

Instantly share code, notes, and snippets.

@MostlyFocusedMike
Created June 10, 2018 22:01
Show Gist options
  • Save MostlyFocusedMike/2f44e904f5b679fb36855c1486e30811 to your computer and use it in GitHub Desktop.
Save MostlyFocusedMike/2f44e904f5b679fb36855c1486e30811 to your computer and use it in GitHub Desktop.
function grabber(resource, fakeStatus) {
return new Promise((resolve, reject) => {
window.setTimeout(() => {
if (fakeStatus === 200) {
resolve(`load ${resource}`)
} else {
reject("Error")
}
}, 3000);
});
}
grabber("article1", 200)
.then((result) => {
console.log(result);
return grabber("comments", 200)
})
.then((result) => {
console.log(result)
console.log("All loaded!")
})
.catch((result) => console.log(result, "there was an issue"))
console.log("The page assets we don't want to reload");
// LOG: The page assets we don't want to reload
** 3 seconds **
// LOG: load article1
** 3 seconds **
// LOG: load comments
// LOG19 All loaded!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment