Friday 5 May 2017

Strange output of promise - Node.js

I have a very strange issue. I have a variable records which contains database rows:

RowDataPacket { id_feature_flag: 104, id_test_case: 10, value: '125' }
RowDataPacket { id_feature_flag: 106, id_test_case: 10, value: '2' }
RowDataPacket { id_feature_flag: 107, id_test_case: 10, value: '3' }

and code which is bugged:

for(var record of records) {
     flagPromises.push(new Promise((resolve3, reject3) => {    
         console.log(record.id_feature_flag) //returns 104, 106, 107 - OK                             

         _flags.get(record.id_feature_flag).then(flag => {
             console.log(record.id_feature_flag) //returns 107, 107, 107 - not ok
             flag.value = record.value
             resolve3(flag)
         })
    }))
 } 



via Michal Bialek

No comments:

Post a Comment