Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

89
Views
Bloque de finalización de la base de datos en tiempo real de Firebase de Javascript

Estoy tratando de entender firebase-realtime-database. Puedo obtener los datos, pero no sé cómo agregar un bloque de finalización. Quiero decir, ¿hay una función para verificar cuándo se completa mi consulta de obtención de datos?

 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 }

¡Muchos gracias!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

El método once() también devuelve una promesa, por lo que puede usar la lógica habitual de manejo de promesas ( then() / catch() o try / catch ).

Por ejemplo:

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

Actualización : dado que ahora actualizó su código para mostrar que hay varias llamadas once en un bucle, puede usar Promise.all para eso:

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!