3 ms·
Escaping Callback Hell with ClojureScript macros
- chime 15y agoHow does exception/error handling work if you code like this? I'd love to be able to do the same in CoffeeScript.
- falava 15y agoLook at http://tamejs.org http://tamejs.org library and this threads for CoffeScript implementation: http://news.ycombinator.com/item?id=2776938 http://news.ycombinator.com/item?id=2776938 https://github.com/jashkenas/coffee-script/issues/350 https://github.com/jashkenas/coffee-script/issues/350
- ivanzhao 15y agoCan't wait till this async issue get solved in CoffeeScript. To me it's currently the biggest weakness in the JS family, especially given how much we all rely on the event-based style of programming in this language.
- pufuwozu 15y agoExceptions are interesting. The calls are asynchronous so you can't wrap the whole macro in a single try/catch. See node's wiki for an explanation on why this is a problem: https://github.com/joyent/node/wiki/Async-exception-handling https://github.com/joyent/node/wiki/Async-exception-handling Node encourages people to create functions like: function(err, x) { if(err) handle(err); } This way they avoid the whole async + try/catch problem. It should be possible to define a macro that does something similar. Avoiding that trap, individual try/catch statements still work fine: (timeout/timeout-macro (pn "Hello") (try* (pn (throw "Throwing up")) (catch e (pn (str "There was an error: " e)))) (pn "World"))