Skip to content

Instantly share code, notes, and snippets.

@kkeeth
Last active March 20, 2020 03:11
Show Gist options
  • Save kkeeth/2bbddaaf5d0980287605dff03e2b444d to your computer and use it in GitHub Desktop.
Save kkeeth/2bbddaaf5d0980287605dff03e2b444d to your computer and use it in GitHub Desktop.
// then-catch-final(then)
const taskA = () => {
console.log("Task A")
throw new Error("throw Error at taskA")
}
const taskB = () => {
console.log("Task B") // does not be call
}
const onRejected = (error) => {
console.error(error) // => "throw Error at taskA"
}
const finalTask = () => {
console.log("Final Task")
}
Promise.resolve()
.then(taskA)
.then(taskB)
.catch(onRejected)
.then(finalTask)
// onload or dom content loaded
const onReady = () => {
return new Promise((resolve) => {
const readyState = document.readyState
if (
readyState === "interactive" ||
readyState === "complete"
) {
resolve()
} else {
window.addEventListener("DOMContentLoaded", resolve)
}
})
}
onReady().then(() => {
console.log("DOM fully loaded and parsed")
})
console.log("==Starting==")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment