Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

161
Visualizações
Should I remove "await" keyword to increase response time?

I've database of users where they have created their team. and other document for storing racers.

each user can create a team of 6 racers.

but the problem is that I've 50k users and using the below code to remove a racer from their team if Admin deleted it from Racers Document.

I'm using express.js and mongoose

team is an array of object which has racers name, it's shortCode and unique identifier.

async function delete(req, body){
    // code to validate users input
    await Users.updateMany({'tema.shortCode': 'HAM'}, { $pull: {'team.shortCode': 'HAM'}})

}

I've seen that response time decreases if i remove await keyword. But is it recommended to do that.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

No, you shouldn't remove the await. Removing the await means that if the Users.updateMany call rejects, the error won't be able to be handled easily as it would become an unhandled promise rejection.

const fail = async message => Promise.reject(message)

const usingAwait = async () => {
  await fail('using await')
}


const noAwait = async () => {
  fail('no await')
}

const handleError = error => console.log('Handled error:', error)

;(async () => {
  await usingAwait().catch(handleError) // logs Handled error: using await
  await noAwait().catch(handleError) // doesn't log anything!
})()

The typescript-eslint rule @typescript-eslint/no-floating-promises has some more details on this:

Unhandled promises can cause several issues, such as improperly sequenced operations, ignored Promise rejections and more. Valid ways of handling a Promise-valued statement include awaiting, returning, and either calling .then() with two arguments or .catch() with one argument.

The way to speed things up would be to use something like Promise.all if you're doing multiple deletes that don't depend on the result of each other:

const reqs = [[req1, body1], /* ... */]
await Promise.all(reqs.map(async ([req, body]) => delete(req, body))
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda