Answer the question
In order to leave comments, you need to log in
How to run a method in parallel with server operation?
There is a method that works for 40 minutes:
let promises = some.map(el => {
return new Promise((res ,rej) => {
...some action
})
})
await Promise.all(promises)
comareData() {
return new Promise(async (res, rej) => {
await someOtherFunctions();
...
updateDB()
.then(data => res(data))
.catch(err => rej(data))
})
}
comareData(); //Далее запуск без тега await
Answer the question
In order to leave comments, you need to log in
IMHO this is not correct, you must have a server independent of any workers to work with
the database IMHO working with the database as a whole can lead to blocks of the database itself as a result of denials of service. it is worth analyzing separately.
suppose your server should receive a command to start any such action, ok, then do it through the queue, through the second server that receives the command from the first one, whatever, as long as you don’t lock your main process
and yes, your comareData function is a masterpiece of misunderstanding of promises and async functions, this gap is a reason to fix it.
at least now I see that your promise will never resolve if someOtherFunctions throws an exception
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question