title: Time delay in child_added listener
body: <p>I  want to add a new team member if team member not exists in the Firebase database. However I see a time delay while reading the existing entries. The below code returns null for the variable <code>teammembertKey</code>. Therefore I see a new key in database every time I re-login into the system. Can someone help me to solve this issue?</p>
  
  <pre><code> checkIfUserExists = function (teammemberData) {
            return firebase.database().ref().child('/leaders/' + firebase.auth().currentUser.uid)
                .once("value", function (snapshot) {
                    console.log(snapshot.exists());
                return Promise.resolve({
                    teammemberData,
                    userExists: snapshot.exists(),
                });
            });
        };
  
        $scope.submit = function () {
            var teammembertKey = null;
            // A teammember entry.
  
            // A teammember entry.
            var teammemberData = {
                uid: firebase.auth().currentUser.uid,
                email: firebase.auth().currentUser.email,
                displayName: firebase.auth().currentUser.displayName,
                photoURL: firebase.auth().currentUser.photoURL
            };
            const p = checkIfUserExists(teammemberData);
  
            p.then((snapshot, userExists) =&gt; {
                if (userExists) {
                    teammembertKey = snapshot.key;
                    // update user
                } else {
                    // go create a user
                    console.log('i');
                }
            })
             .catch(err =&gt; {
                 console.warn('Error signing in.', err);
             });
  
            if (teammembertKey == null) {
                // Get a key for a new team member.
                teammembertKey = firebase.auth().currentUser.uid; //firebase.database().ref().push().key;
                // Write the new member's data simultaneously.
                var updates = {};
  
                updates['/leaders/' + teammembertKey] = teammemberData;
                const promise = firebase.database().ref().update(updates);
                promise
                  .then(e =&gt; { })
                  .catch(e =&gt; {
                      console.log(e);
                  })
            }
  
        };
  </code></pre>