O
O
onekrugoikov2021-01-31 03:49:39
JavaScript
onekrugoikov, 2021-01-31 03:49:39

How to wait for queries to complete in a loop?

I have a large database of cart accounts, I need to run it and send messages to everyone, here is the code:

users.map(async (user) => {
    bot.sendMessage(user.from_id, 'hollo habr')
})


Roughly speaking, he asynchronously sends all requests at once and goes further, but many of them do not reach, what to do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shamanov, 2021-02-01
@SilenceOfWinter

if the request is successful, delete the record from users + wrap the loop in while (users.length > 0)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question