Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

86
Vistas
Javascript Firebase RealTime Database Completion Block

I am trying to understand firebase-realtime-database. I am able to fetch the data, but I do not know how to add a completion block. I mean, is there a function to check when my data fetch query is completed?

function getData() { 
  firebase.database().ref('SectionNames').once('value', function(names) {    
    names.val().forEach(function(sectionname) { 
      firebase.database().ref('Sections').child(sectionname).once('value').then( function(child)  

      //code

    });   
   });
  });
 //Completion block or a method to call processData() after I get all the sections
}

function processData() {
 //call this function after you get all the sections
}

Thank you very much!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The once() method also returns a promise, so you can use the usual promise handling logic (then()/catch() or try/catch).

For example:

function getData() async { 
  let names = await firebase.database().ref('sections').once('value');
  processData(names);
}

Update: since you now updated your code to show there are multiple once calls in a loop, you can use a Promise.all for that:

function getData() { 
  firebase.database().ref('SectionNames').once('value', function(names) {    
    let promises = [];
    names.val().forEach(function(sectionname) { 
      promises.push( 
        firebase.database().ref('Sections').child(sectionname).once('value')
      );
    });   
    Promise.all(promises).then((snapshots) => {
      processData(snapshots);
    });
  });
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda