Dealing with race conditions
JavaScript
function foo(id) {
/* some statements */
bar(id);
}
function(
function bar(id) {
try {
throw {
name: "Exception",
message: "oooh damn!" + id
}
} catch (e) {
console.error(e.name, e.message);
}
}
setTimeout(function () { foo(1); }, 10);
setTimeout(function () { foo(2); }, 10);