無法弄清楚爲什麼'describeDir'諾言鏈不能接受..任何人有一個想法,我在這裏搞砸了嗎?所有的代碼似乎都會執行,但是任何承諾api函數,例如那麼或最後永遠不會執行。下面顯示了兩個頂級功能。 github回購點位於https://github.com/PhoenixContactUSA/pcworx-doc-genPromise chain then then-able
function updateDescriptor(fileloc, wsName, outdir){
console.log('Updating descriptor file for: ' + wsName);
return new Promise(function(resolve, reject){
return getDescriptor(outdir).then(
(value) => {
let descriptorFile = value;
var comments = getComments(fileloc);
var variables = getVariables(fileloc);
//wait until both are completed before continuing
return Promise.all([comments, variables]).then((values) => {
//var descriptor = new Object();
//console.log(JSON.stringify(descriptor));
descriptorFile[wsName] = new Object();
//console.log(JSON.stringify(descriptor));
//var worksheet = new Object();
descriptorFile[wsName].comments = values[0];
descriptorFile[wsName].variables = values[1];
//save the file
return saveDescriptor(descriptorFile, outdir).then((value) => {
console.log('Completed ' + wsName + ' ' + value);
resolve(value);
}, (reason) => {console.log(reason)})
}, (reason) => {
console.log(reason);
}
)
},
(reason) => {console.log(reason)}
)
})
}
function describeDir(filedir, outdir){
var files = findFilesInDir(filedir, '.XML');
for (var k=0;k<files.length;k++){
if ((files[k].indexOf('@HW') !== -1) || (files[k].indexOf('@LIBS') !== -1) || (files[k].indexOf('@ROOT') !== -1) || (files[k].indexOf('run') !== -1)) {
files.splice(k,1);
}
}
return Promise.each(files, function(file){
return updateDescriptor(file, path.basename(file), outdir);
});
}
然後我在這裏調用函數。代碼似乎執行得很好,但是從不調用then()。請注意,我在這個最新版本中使用了藍鳥。
//generate the output files, then copy them to the destination
docProcessor.describeDir(folder, path.join(__dirname, '..')).then((value)=>{
console.log('docProcessor then entered: ' + value);
});
您可以包括或指明對您正試圖'then'承諾鏈條行? – TheHansinator
您是否收到任何錯誤? –
沒有錯誤。它是基於節點的,一半的問題是我目前沒有得到任何調試信息。 – zmink1