Jake task firing complete before completion of async task

I am testing Jake out as a possible replacement for Rake on a primarily javascript project. Now one thing that I am finding as odd is that the completion event is being triggered BEFORE the event has completed.

Here is an example:

task('some_task_1', {async: true}, function () {
    console.log("|- Doing something");

    var execCallback = function() {
        console.log("  |- Done something");
        complete();
    };

    setTimeout(execCallback, 2000);
});

task('some_task_2', {async: true}, function () {
    console.log("|- Doing something else");

    var execCallback = function() {
        console.log("  |- Done something else");
        complete();
    };

    setTimeout(execCallback, 2000);
});

task('task_runner', {async: true}, function () {
    var firstTask = jake.Task['some_task_1'];
    var secondTask = jake.Task['some_task_2'];

    firstTask.addListener("complete", function() { secondTask.invoke(); });
    secondTask.addListener("complete", function() { complete(); });

    firstTask.invoke();
});

task('default', function () {
    jake.Task['task_runner'].invoke();
});

I would have expected that the output would be:

|- Doing something
   |- Done something
|- Doing something else
   |- Done something else

However what I actually get is:

|- Doing something
|- Doing something else
   |- Done something
   |- Done something else

So is there some magic around how the async should be working in Jake? as it seems to be somehow firing a complete event before its actually finished the exec.

== EDIT ==

Just so there is no confusion I am using version 0.5.16 of Jake https://github.com/mde/jake

== EDIT 2 ==

Have posted another example which now should show the exact issue in a clearer way as it seems to be related to tasks within tasks which are async.

There seems to be a change of behaviour (not sure if it's bug or feature) between node 0.8 to 0.10. Jake tasks that were executing sequentially in 0.8.14 (with async:true) seem to start running concurrently in 0.10.x

Try uninstalling node 0.10, and install 0.8 instead.

I just ran this locally with the same Jake (v0.5.16). I had to correct the syntax -- you need a comma after your opts object, and I made the command the true command, just so there'd be something to run:

task('some_task_1', {async: true}, function () {
    console.log("|- Doing something");

    var command = "true";
    jake.exec(command, {}, function(){
        console.log("   |- Completed doing something");
        complete();
    });
});

task('some_task_2', {async: true}, function () {
    console.log("|- Doing something else");

    var command = "true";
    jake.exec(command, {}, function(){
        console.log("   |- Completed doing something else");
        complete();
    });
});

task('some_task_root', {async: true}, function () {
    var firstTask = jake.Task['some_task_1'];
    var secondTask = jake.Task['some_task_2'];

    firstTask.addListener("complete", function() { secondTask.invoke(); });
    secondTask.addListener("complete", function() { complete(); });

    firstTask.invoke();
});

That's all I changed, but I got the correct output, not what you describe:

$ jake some_task_root
|- Doing something
   |- Completed doing something
|- Doing something else
   |- Completed doing something else

Looks like you've also opened a GitHub Issue for this (https://github.com/mde/jake/issues/202), so let's resolve it over there on the Issue. The minimal example works correctly, so there must be something specific with your build script. Let's get some more details and try to get you sorted out. :)