Thursday, 13 April 2017

Promise for loop - basic

What's the best way to loop through this Promise chain ? code works fine without the 'for loop' with last step saving JSON in MongoDB. After the first iteration NodeJS shell hangs.

    for(i=0; i < 2; i++){
    forLoop(countOfFlights,jsonRead).then(function(fromResolve){
    return filter(fromResolve)
    }).then(function(fromResolve){
    return sort(fromResolve)
    }).then(function(fromResolve){
        saveMongoDB(fromResolve)
    })}

I checked some of the threads on Promise & looping, but the examples were too complicated for me. Perhaps just one magic line would solve it. I'm sure better understanding of why it hangs would be beneficial too.

Kind regards,



via user7861743

No comments:

Post a Comment