I have an async function fileUpload()
which uploads files to a server and returns a promise when it is done. When a user wants to submit a different form, the submitForm()
will await fileUpload
before posting the form.
While it waits for await fileUpload
, I would like to tell the user that the system is waiting for uploads to finish. Here is what I imagined (but obviously cannot work):
async fileUpload() {
await Promise.all(
// Does a for loop here and uploads all files
)
}
async submitForm() {
const FormBody = new FormData();
await fileUpload; // I want to set this.IsUploading = true if awaiting. If not awaiting, then this.IsUploading = false;
this.$axios.post('/api', FormBody)
}
I use await fileUpload
without the parenthesis because if I do await fileUpload()
then it is invoking that function again. But how can I set this.IsUploading
to true
while awaiting for fileUpload()
to finish and then set it to false
if there is nothing more to wait for?
Maybe just set the variable before and after the
await
call?