Dealing with race conditions

by Amy L

JavaScript

function foo(id) {
    /* some statements */
    bar(id);
}

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);