Skip to content

Instantly share code, notes, and snippets.

@internetimagery
Created February 11, 2017 08:21
Show Gist options
  • Select an option

  • Save internetimagery/3f39e105c8727b6cf71ad44f76ed8e81 to your computer and use it in GitHub Desktop.

Select an option

Save internetimagery/3f39e105c8727b6cf71ad44f76ed8e81 to your computer and use it in GitHub Desktop.
# Automatically return the callback if errored
e = (cb1, cb2)-> return (err, args...)-> if err then cb1 err else cb2 args...
# Demo
div = (num1, num2, callback)->
try
callback null, num1 / num2
catch err
callback err
# Outer function
main = (cb)->
# Divide some numbers
div 10, 2, e cb, (result)->
console.log result
div 15, 3, e cb, (result)->
console.log result
div 20, 0, e cb, (result)->
console.log result
# Go!
main (err)->
console.error err
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment