Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

173
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda