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

169
Visualizações
Trying to make a function asynchronous to perform an action only after uploading data

Edited to add question at the bottom: This currently functions appropriately, except that it's not running asynchronously (which I thought it was hence the async await attempts).

My question is how to make a submit flow asynchronous so that I can perform an action (in this case prompt the user for preferred next steps) only after upload of info.

 const handleSubmit = async () => {
  
  try {
    if (image.value) {
      await uploadImage(image.value); <--I thought this was 
        asynchronous, but I tested and I don't think it is. 
    }

    const colRef = collection(db, "collection");

    //I thought the below was asynchronous, but it's not
    await addDoc(colRef, 
       {
      data: data.value <--placeholder
     
    });
    
      });
  } catch {

  }

  //code to run after addDoc is done, but it runs immediately
  $q.dialog({
      [content]
    })
};

UPDATE: I have changed the addDoc function with a .then function, and that seems to work. The current issue is that I can't make the uploadImage function complete before running the addDoc function.

Here is my attempt at promisifying the uploadImage function, and I know it's sloppy and wrong:

 if (image.value) {
          return new Promise((resolve, reject) => {
            const newImage = uploadImage(image.value);
            resolve(newImage);
          });
        } else {
          console.log("error");
        }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The async/await method you're trying to use will only work as you intend if your uploadImage() and addDoc() functions return JavaScript Promises.

See this article from nodejs.dev on async/await for more information.

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