runing async function like sync in node js

Viewed 20

I get problems, when I try to execute two async function. This is my first function that download images in specific folders.

const getLayerData = async (Collection_id) => {
  let layers_data = await getLayersID(Collection_id);
  //let collection_name = await getcollecionName(Collection_id);
  return new Promise(function(resolve, reject) {
    layers_data.forEach((value, key) => {    
      getTraitData(key, value);
    });
    console.log('finish downloading layers');

  });  
};

My second function allow it to resize images, modified and upload it to firestore.

To run both, I read states in the firestore to do tasks. When it runs, only one async is execute.

const start = async () => {
  var users = await readStates();
  var task = users.length;
  while (true) {
    
    if (task > 0){
      users.forEach(data => { 

        // download layers

        buildSetup(); //sync
        getLayerData(data[1)]; //async 
        startCreating(); //async allow resize, modify, upload to firestore, storage
         
        
        //espera (data);
        //runTask();

        //end task processs
        task = task - 1;

      });
    }else{
      //console.log(task);
      break;
    };
  };
}; 
0 Answers
Related