i want that the two functions with await keyword executes first then the alert() and location.reload should be executed.
async function CompleteUpload(){
await LoadValues();
await UploaderMethod();
alert("Product Added Successfully!");
location.reload();
}
the alert just pops before the 2 await function calls and also the page gets reloaded before these methods are executed.
async function LoadValues(){
prName = document.getElementById('NAMEbox').value;
proc = document.getElementById('PROCbox').value;
}
async function UploaderMethod(){
var uploadTask = firebase.storage().ref("Laptops/Img" + id+".png").put(files[0]);
uploadTask.on('state_changed', function(snapshot){
}, .... //firebase upload data function
the upload CompleteUpload() works perfectly if i don't put alert() and reload at the end.
UPDATED** (after someone answered about returning a promise)
at the end of upload task i wrote this:
return new Promise(function(resolve, reject) {
resolve("yeah");
}
changed the complete upload to:
function CompleteUpload(){
LoadValues();
UploaderMethod().then(Reeeload());
}
function Reeeload(){
alert("Product Added Successfully!");
location.reload();
}