I try to work with JS promises, using jQuery. I have a chain of promises like this:
function myPromisesChain(data)
{
    return $.when(data)
        .then(firstStep)
        .then(secondptStep)
        .then(thirdStep)
        // ...n Step
        .then(finalStep)
        .always(function(data){
            console.log('FINISHED: ' + JSON.stringify(data));
        });
}
That`s fine, but what to do, if I need to execute a step in a loop? Sad, but I cannot find a correct syntax so far... I expect something like this (approximately):
    function myPromisesChain(data)
{
    return $.when(data)
        .then(firstStep)
        .then(secondptStep)            
        .then(function(data){
            var counter = 0;
            var limit = 3;
            while(counter<limit){
                  thirdStep(data.transaction[counter]);
                  counter++;
            }
            return data;
        })
        // ...n Step
        .then(finalStep)
        .always(function(data){
            console.log('FINISHED: ' + JSON.stringify(data));
        });
}
Problem is that function in a loop is a promise itself.
 
     
    