Question: I want to perform an operation repeatedly, with an increasing timeout between each operation, until it succeeds or a certain amount of time elapses. How do I structure this with promises in Q?

Answer: 
All the answers here are really complicated in my opinion. Kos has the right idea but you can shorten the code by writing more idiomatic promise code:

```
function retry(operation, delay) {
    return operation().catch(function(reason) {
        return Q.delay(delay).then(retry.bind(null, operation, delay * 2));
    });
}

```

And with comments:

```
function retry(operation, delay) {
    return operation(). // run the operation
        catch(function(reason) { // if it fails
            return Q.delay(delay). // delay 
               // retry with more time
               then(retry.bind(null, operation, delay * 2)); 
        });
}

```

If you want to time it out after a certain time (let's say 10 seconds , you can simply do:

```
var promise = retry(operation, 1000).timeout(10000);

```

That functionality is built right into Q, no need to reinvent it :)
1. Assign a boolean variable for "all process timeout".
2. Call window's setTimeout to make that variable 'false' after that "all process timeout".
3. Call promise operation with a timeout.
4. If it succeeds no problem.
5. If it fails: In promise's error handler, call promise function again with an increased timeout if the boolean variable is true.

Something like this:

```
var goOn= true;

setTimeout(function () {
    goOn= false;
}, 30000); // 30 seconds -- all process timeout

var timeout = 1000; // 1 second

(function () {
    var helperFunction = function () {

        callAsyncFunc().then(function () {
            // success...
        }, function () {
            // fail
            if (goOn) {
                timeout += 1000; // increase timeout 1 second
                helperFunction();
            }
        }).timeout(timeout);

    }
})();

```