1

i apologize if it is already asked but i have searched all over the internet and nothing has worked i am working with firestore and javascript i have tried this by far & a lot of other things

var App

  function A (){

    firebase.database().ref('Info/').once('value').then(function(snapshot){
      var Ipz = (snapshot.val() && snapshot.val().Iplist) || 'Anonymous';
      console.log(Ipz)
     })

    console.log('A')
   }


   function B (){
    console.log('B')
   }


      App = Promise.resolve();

      App = App.then(A).then(B);

      App.then(() => {
      console.log("All done");
        })

my output :-

A
B
All done
JdGJtwEe8rb394BlX4IkjUfH4Wv1;JdGJtwEe8rb394BlX4IkjUfH4Wv1;

while i want this output

JdGJtwEe8rb394BlX4IkjUfH4Wv1;JdGJtwEe8rb394BlX4IkjUfH4Wv1;
A
B
All done
1

1 Answer 1

3

You need to chain the asynchronous database function with the A, B, and all done functions using .then to connect each one:

function lookup() {
  return firebase.database().ref('Info/').once('value')
    .then(function(snapshot) {
      var Ipz = (snapshot.val() && snapshot.val().Iplist) || 'Anonymous';
      console.log(Ipz)
      // if you want to pass Ipz to `A` as a parameter, then `return Ipz;` here
    });
}
function A() {
  console.log('A');
}
function B() {
  console.log('B');
}
lookup()
  .then(A)
  .then(B)
  .then(() => console.log("All done"));
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.