What is the best way to detect when all of my asynchronous calls are finished then trigger another function? I have three querys that are triggered by the user picking a topic. These querys run and their return values are then combined to be used in a new function. The problem is I need to know when they are all done then run the new function.

```
function queryHandler1() {
    // do something
    return result1;
}

function queryHandler2() {
    // do something
    return result2;
}

function queryHandler3() {
    // do something
    return result3;
}

function alldone(result1, result2, result3) {
     // do something
    return result4;
}

```

I have tried using jquery.when(), but it only runs the first time and when the user picks a new option it does not trigger alldone?

```
// global
var d1 = $.Deferred();
var d2 = $.Deferred();
var d3 = $.Deferred();

function queryHandler1() {
    // do something
    d1.resolve();
    return result1;
}

function queryHandler2() {
    // do something
    d2.resolve();
    return result2;
}

function queryHandler3() {
    // do something
    d3.resolve();
    return result3;
}

function alldone(result1, result2, result3) {
     // do something
    return result4;
}

// the top level $.when
$.when(d1, d2, d3).done(function() {
    alldone();
});

```

How do I reset the deferred or resolve so that all done is triggered again?

Thanks for the help!