我对promise 很陌生,并试图让Promises.All在这种情况下发挥作用. 然而,当我try 通过调用changeFile函数来运行代码时,它会立即到达Promises.all then方法中的console.log行. 我做错了什么?
let doc1Text = "";
let doc2Text = "";
const processDoc = async (fileInput) => {
var input = document.getElementById(fileInput);
await fetch(urls.GetContractLanguageText, {
method: 'POST',
body: input.files[0]
})
.then(j => j.json())
.then(x => {
return x.ConvertedText;
});
}
const processDoc1 = async () => {
$(selectors.fileProgress1).val(0);
doc1Text = await processDoc(selectors.baseFile);
$(selectors.fileProgress1).val(100);
};
const processDoc2 = async () => {
$(selectors.fileProgress2).val(0);
doc1Text = await processDoc(selectors.newFile);
$(selectors.fileProgress2).val(100);
};
const processFiles = async () => {
$(selectors.aiComparison).removeClass(selectors.hide);
await Promise.all([processDoc1, processDoc2])
.then(() => {
console.log(doc1Text, doc2Text);
});
}