S
S
Soft_touch_plastic2021-06-24 13:55:18
Node.js
Soft_touch_plastic, 2021-06-24 13:55:18

How to solve this asynchronous task?

Hello, I'm not that good at asynchronous programming yet, and this task blows my mind:
I have an array of unchecked proxies, which I pass to the checkProxy function, from which I would like to receive a promise with checked proxies:

checkProxy(proxies).then(valid_proxies => {
        console.log(valid_proxies) //в valid_proxies лежит массив отвалидированных прокси
})

Checking one proxy or proxy-check looks like this:
proxy_check(proxy).then(r => {
     // прокси рабочий
});

It turns out that I need to iterate over all elements of the proxies array and call proxy_check for each, but I don’t understand how to wait for all checks to complete and return an array of only proxies that passed the test. Can you help with this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2021-06-24
@Soft_touch_plastic

Promise.all(proxies.map((p) => check(p)))
.then((check_results) => check_results.filter(....))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question