title: Returning Promise after Firebase Query
body: <p>Trying to make this as general so it can help other people. This question is more me struggling with the concepts of promises.</p>
  
  <p>So I have a function that returns the value of a boolean variable. My idea is to pull some data off of Firebase, and then I was looping through the values... to then set the variable to true if found.</p>
  
  <p>The issue that I was running into was that the value would be returned regardless of if the ForEach loop and the query were complete. I attempted to use some sort of promise resolving (in the code snippit below) to return it properly</p>
  
  <pre><code>export function CheckIfFriendsPending(id2){
      var userID = getFirebase().auth().currentUser.uid
      var indicator = false
  
       var retri = function()
      {   
             getFirebase().database().ref('members/' + userID + '/PendingFR').once('value').then(function(snap) {
                      console.log("~~~~~~~~~~~~~~~~~~go")
  
                      //if(result.hasOwnProperty('install_type'))
                      snap.forEach(function(childSnapshot) {
  
                          var childObject = childSnapshot.val()
                          if(childObject.hasOwnProperty('From')){
                              alert("OKAY")
                              if(childObject.From == userID &amp;&amp; childObject.To == id2){
                                  indicator = true
                              } else if(childObject.From == id2 &amp;&amp; childObject.To == userID){
                                  indicator = true
  
                              }
                          }
  
                      });
  
  
                  })                          
      } // end retri
  
      Promise.all(retri).then(function() {
          return indicator
      })
  }
  </code></pre>
  
  <p>Anyone have any idea for how to approach this? I guess a <strong>summarized version</strong> question is how to create a promise within a function that already returns a promise (which I believe the firebase database querys do). I guess it would have to wait for "ForEach" loop to resolve completely as well.</p>