Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!