この関数を同期して実行します。私のアプリケーションでは、 は、それが他のデータに割り当てられる前に供給源を作成する必要があります。 そして、このタスクが完了した場合にのみ、アプリケーションはさらに進んでください。 それ以外のデータが作成され、SupplySourceIdが見つからない(undefinded)ため、失敗します。この関数をnode.jsで同期的に実行するには
ここで私は、同期機能を開始します。
var articleSupplySourceId = processSupplySource();
機能ProcessSupplySource(processSupplySourceを()):
function processSupplySource(){
var postJson2 = {};
postJson2.articleNumber = entry['part-no'];
postJson2.name = entry['part-no'];
postJson2.taxName = 'Vorsteuer';
postJson2.unitName = 'stk';
postJson2.supplierNumber = "1002";
postJson2.articlePrices = [];
var articlePrices = {};
articlePrices.currencyName = 'GBP';
articlePrices.price = entry['ek-preisgbp'];
articlePrices.priceScaleType = 'SCALE_FROM';
articlePrices.priceScaleValue = '1';
postJson2.articlePrices.push(articlePrices);
return postSupplySource(postJson2);
機能PostSupplySource
function postSupplySource(postJson2) {
rp({
method: 'POST',
url: url + '/webapp/api/v1/articleSupplySource',
auth: {
user: '*',
password: pwd
},
body: postJson2,
json: true
}).then(function (parsedBody) {
console.log('FinishArticleSupplySource');
var r1 = JSON.parse(parsedBody);
console.log(r1.id);
return r1.id;
})
.catch(function (err) {
console.log('errArticleSupplySource');
console.log(err.error);
// POST failed...
});
}
コールバックまたは約束について読む – yBrodsky
することはできません。そして、あなたはすべきではありません。あなたは簡単にそれを非同期かつ*順次実行することができます。 – Bergi