Saturday, 27 May 2017

Firebase Cloud Functions - Synchronous Functions

I´m new to firebase cloud functions. I want to create my index.js as following:

exports.countFruits = functions.database.ref("fruits/{FruitID}").onWrite(event =>{

(...)

    var sauces = [];

    let ref = admin.database().ref("sauces");
    ref.on("child_added", function(snapshot, prevChildKey){

    let sauce = snapshot.val();
    sauces.push(sauce.id);
    });

// -> USE THE COMPLETED ARRAY FOR NEXT ANOTHER PURPOSE

});

So my Problem is, that I want to use the COMPLETED array while it is actually being filled. As a consequence I want to structure my code synchronously so the next function is only executed when all sauce.id are in the array.

How can I code that?

Thank you!



via ktm125

No comments:

Post a Comment