title: How to wait for a Firebase retrieve value and only then exit the function?
body: <p>I have a Firebase query.</p>
  
  <p>Because Firebase works asynchronously, the function continue to run without waiting for the Firebase retrieve value.</p>
  
  <p>Is there a way to wait for the result from the Firebase query and only then to make the return from the function?</p>
  
  <pre><code>  function CheckBuyingCondition(prefix){
  
          var Res= "";
  
              var Current_Price_Open_ref = firebase.database().ref("dailyT/Current_Price_Open/"+nextDayTrading).orderByChild("Prefix").equalTo(prefix)
                  Current_Price_Open_ref.once("value").then(function(snapshot) {
                      if(snapshot.exists()){
                          snapshot.forEach(function(childSnapshot) {  
                var val = childSnapshot.val();
  
                          res =""+ val.Current_Price_Open;
                      }); 
                  }else{ 
                      res = "NA";
                  }
              });
  
              return res; //(Here i got res = "" instead of the correct value from Firebase query
  }
  </code></pre>