I made some DB operations and after some soap calls. Here is the result. It not seemed rigth to me. how can I synchronize them in nodejs? This all are async functions.
here is the code
sccmConnectDB.getAllComputers().then(result => {
computers = result[0]
console.log("select from sccm db is completed...")
caConnectDB.deletezSCCM2CM().then(result => {
console.log("deleting from ca db zsccm2cm table is completed...");
caConnectDB.insertzSCCM2CM(computers).then(result => {
console.log("inserting ca db zsccm2cm table is completed...");
login.login().then(sessionId => {
console.log("login successfull");
getHostName.getHostNames().then(result => {
hostNames = result[0];
console.log("query result for hostname -->", hostNames);
hostNames.forEach(element => {
uuid = "nr:" + element.uuid;
attrVals = { string: ["system_name", element.compName] };
attrbts = { Attributes: [] }
updateObject.updateObject(sessionId, uuid, attrVals, attrbts).then(result => {
console.log("Update successfull");
});
});
logout.logout(sessionId).then(result => {
console.log("logout successfull");
});
});
});
});
});
});
make sync the async,, you can't.. Once something is async everything up the chain has to be async too. But nodejs, does have async/await so can make this a lot easier.then->then->then->thenThen you missed the bit about me saying there isasync / await, that is the reason for it, It's not a direct replacement for sync coding, but syntax wise it makes it look pretty close.. eg, you will need to replace that forEach too, but it's nothing too drastic..