There is an object with data:
obj.user = { "10": { "500": { "rank": "LEADER", "nick": "test1" }, "501": { "rank": "MEMBER", "nick": "test2" } }, "20": { "500": { "rank": "LEADER", "nick": "test1" } } } Further function
var userCache = {} function checkUser(chat, id, callback) { if(userCache[id] === undefined) { request(apiURL, function(err, res, body) { // возвращается json userCache[id] = body; console.log(id + " NEW"); callback(); }) } else { console.log(id + " OLD") } } How to make elements go with obj.user to a function in turn and userCache remembers everything correctly. I wrote this code here:
Object.keys(obj.user).reduce((promiseChain, chat) => { return promiseChain.then(() => new Promise((resolve) => { for(var id in obj.user[chat]) { checkUser(chat, id, resolve); } })); }, Promise.resolve()); but for some reason it processes about 40 users and stops.
resolve? - Grundy