vendredi 18 janvier 2019

Stop if statement in async function from returning undefined instantly? [duplicate]

This question already has an answer here:

I've got the following async code.

const dlcOrNot = async (file) => {
  console.log('Unpacking dlc file...')
  if (file.indexOf('.dlc') > -1) {
    await decrypt.upload(file, (err, response) => {
      const links = response.success.links;
      writeFile('urls.txt', String(links).replace(/,/g, '\n'), 'utf-8', () => {
        return 'urls.txt';
      });
    });
  } else {
    return file;
  };
};

My problem is the if statement returns undefined instantly before decrypt.upload() ran, how can I make it wait for the function inside to return its value?

Aucun commentaire:

Enregistrer un commentaire