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: 
Here's an example of how I'd approach this, with some helper functions. Note, the 'maxTimeout' is the more complicated part because you have to race two states.

```
// Helper delay function to wait a specific amount of time.
function delay(time){
    return new Promise(function(resolve){
        setTimeout(resolve, time);
    });
}

// A function to just keep retrying forever.
function runFunctionWithRetries(func, initialTimeout, increment){
    return func().catch(function(err){
        return delay(initialTimeout).then(function(){
            return runFunctionWithRetries(
                    func, initialTimeout + increment, increment);
        });
    });
}

// Helper to retry a function, with incrementing and a max timeout.
function runFunctionWithRetriesAndMaxTimeout(
        func, initialTimeout, increment, maxTimeout){

    var overallTimeout = delay(maxTimeout).then(function(){
        // Reset the function so that it will succeed and no 
        // longer keep retrying.
        func = function(){ return Promise.resolve() };
        throw new Error('Function hit the maximum timeout');
    });

    // Keep trying to execute 'func' forever.
    var operation = runFunctionWithRetries(function(){
        return func();
    }, initialTimeout, increment);

    // Wait for either the retries to succeed, or the timeout to be hit.
    return Promise.race([operation, overallTimeout]);
}

```

Then to use these helpers, you'd do something like this:

```
// Your function that creates a promise for your task.
function doSomething(){
    return new Promise(...);
}

runFunctionWithRetriesAndMaxTimeout(function(){
    return doSomething();
}, 1000 /* start at 1s per try */, 500 /* inc by .5s */, 30000 /* max 30s */);

```
My sugesstion would be to use the `bluebird-retry` library

To install

`npm i bluebird-retry`

```
 var Promise = require('bluebird');
 var retry = require('bluebird-retry');
 var count = 0;
function myfunc() {
    console.log('myfunc called ' + (++count) + ' times '+new Date().toISOString());
    return Promise.reject(new Error(''));
}
retry(myfunc,{ max_tries: 5, interval: 5000, backoff: 2 })
    .then(function(result) {
        console.log(result);
    });

```

The above program tries the promise flow 5 times with `interval * backoff` backoff interval between every retry.

Also, should you require to pass any arguments, pass it as `args` which accepts array of arguments. Include it in options section where `max_retries`, `interval` and `backoff` is mentioned.

Here is the official documentation <https://www.npmjs.com/package/bluebird-retry>