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

173
Visualizações
await IIFE result vs separate async function

I have been refactoring some legacy code and found the following example:

    // inside other function
    const isTriggerValid = await (async () => {
        try {
            const triggers = await db.any(getTriggerBeforeBook, { paramId });
            if (!triggers || triggers.length === 0) {
                return false;
            }

            return true;
        } catch (e) {
            logger.error(e);
            return false;
        }
    })();

and I'd like to ask, what is the point between it, and the code below?

   const isTriggerValid = async (paramId) => {
     try {
        const triggers = await db.any(getTriggerBeforeBook, { paramId });
          if (!triggers || triggers.length === 0) {
              return false;
          }
        return true;
     } catch {
        return true;
     }
   }

And then invoking it with const trigger = await isTriggerValid(paramId) ?

I know absolutely for sure that this keyword hasn't been used in it.

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

0

The main difference would be that in the old version isTriggerValid would be the functions result and in the new one it's a function and the result would be called trigger. Other than that both are invoking the same function.

Regarding your concern about this. In both variants it's an arrow-function inheriting the parent-context so even if it was used it would be the same in both.

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