Execute non-blocking task after blocking tasks
<p>In my application I have <em>n</em> blocking tasks, once all blocking tasks are done executing, I want to finally execute my non-blocking task (which relies on data from these blocking tasks).</p>

<p>My current solution is to have a variable <em>i</em> getting incremented by one in the blocking callback, afterwards it checks if <em>i</em> is <em>n</em>, if so, it executes the dependent, non-blocking task.</p>

<p>However, I feel this is nowhere near perfect; I assume it's a fundamental issue with async programming with a good solution (although I've been unable to find a better one).</p>

<pre><code>var i;

var result_one = null;
var result_two = null;

function render() {
    if (i == 2) {
        // do something with result_one and result_two
    }
}

blocking.call(function(result) {
    result_one = result;
    i++;
    render();
});

blocking.call2(function(result) {
    result_two = result;
    i++;
    render();
});
</code></pre>
