Dealing with race conditions

by robatwilliams

JavaScript

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

function bar(id) {
    try {
        throw new Error(id);
    } catch (e) {
        console.error(e.name, e.message);
        console.log(e.stack);
    }
}

setTimeout(function () { foo(1); }, 10);
setTimeout(function () { foo(2); }, 10);