I'm new to JavaScript and I am really confused about the documentation for promises. I have the following case, when I have a bunch of users, and for each user I execute the async function, in which I do some calculations for this user and add the result with the user to the array. From what I understood from the documentation, I need to get a promise every time the asynchronization function is executed, and add all the promises to the list of promises that allow when the resulting array is passed to it as follows:
someFunction = () => {
var promises = [];
users.forEach(user => {
var promise = asyncFunction(user).callback(callBackValue => {
if (checksAreGood) {
usersArray.push({user: user, result: callBackValue});
}
});
promises.push(promise);
});
return Promise.all(promises).then(() => Promise.resolve(matches));
};
: , , , , 20, , , 20, . , , 20 .
, , . , 1000 , , async , 20.