Skip to content

Instantly share code, notes, and snippets.

@edersonbadeca
Created January 30, 2022 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edersonbadeca/37431261a536d760afd9616a5505d0ce to your computer and use it in GitHub Desktop.
Save edersonbadeca/37431261a536d760afd9616a5505d0ce to your computer and use it in GitHub Desktop.
Sometimes we need to stop a iteration
function Stop(r) {
function Reason () { throw new Error(r) }
return Reason
}
function StopChain(r, fn) {
return fn(r)
}
const error = StopChain('NOT_FOUND', Stop)
try {
error()
} catch (e) {
console.log(e)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment