on async programming, we use lots of callbacks, like this:
var running = function(){
do_sth();
$.post("/xxx", function(data){
do_sth2();
$.get("/ttt", function(data){
do_sth3();
}
}
}
and I think things should be like this:
var running = do_async(function(){
do_sth();
var data = $.post("/xxx");
do_sth2();
data = $.get("/ttt");
do_sth3();
});
How can I do that?
and there is a project on this: https://github.com/JeffreyZhao/jscex
and I think this project is not that easy to use (implementation is by parse the source code)
maybe in the future, we have a native javascript support on this?
I did some research on this, found some disscussion and library here for reference:
https://github.com/JeffreyZhao/jscex
defer coffeescript https://github.com/jashkenas/coffee-script/issues/350
merge into coffeescript: https://github.com/jashkenas/coffee-script/issues/350
tamejs library http://tamejs.org/
stratifiedjs http://onilabs.com/stratifiedjs
kaffeine http://weepy.github.com/kaffeine/
wiki page about this: http://en.wikipedia.org/wiki/Continuation-passing_style
It is not very easy to add a library to support it,
maybe in the future, javascript will add a "defer" keyword.
same question: Pattern for wrapping an Asynchronous JavaScript function to make it synchronous