3 ms·
IMO, a better pattern is to use lexical closures in continuation-passing style to share state: function sleep(time, continuation) { setTimeout(cont
by psykotic 16y ago
IMO, a better pattern is to use lexical closures in continuation-passing style to share state:
function sleep(time, continuation) {
setTimeout(continuation, time);
}
function start_process(x) {
var y = foo(x);
sleep(1000, function() {
var z = bar(x, y);
sleep(2000, function() {
baz(x, y, z);
});});
}
start_process(42);
- geuis 16y agoExcept that you basically wrote the same thing as my second example, except your functions aren't namespaced and are polluting globals.