Created
February 11, 2017 08:21
-
-
Save internetimagery/3f39e105c8727b6cf71ad44f76ed8e81 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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