iced coffeescript - How to use IcedCoffeeScript in function with two callbacks? -


let's assume have such function (in javascript):

function fun(success_cb, error_cb) {   var result;   try {     result = function_that_calculates_result();     success_cb(result);   } catch (e) {     error_cb(e);   } } 

and use like:

 fun(function(result) {   console.log(result); }, function(error) {   console.log(error.message); }); 

how can rewrite usage of function in icedcoffeescript await , defer?

i don't think there optimal way in iced coffee script, although post has interesting suggestions: iced coffee script multiple callbacks

i stick vanilla coffee script:

this how function writtent in coffee-script

fun = (success_cb, error_cb) ->   try     result = function_that_calculates_result()     success_cb result   catch e     error_cb e 

and how call in coffee script

fun (result) ->   console.log result , (error) ->   console.log error.message 

if can rewrite fun function in "errback" style (err, result) in coffee script, be:

fun = (callback) ->   try     result = function_that_calculates_result()     callback null, result   catch e     callback e 

you use in iced coffeescript

await fun defer error, result if error   console.log error.message else   console.log result 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -