Answer the question
In order to leave comments, you need to log in
How to get away from callback hell in node.js?
Hello.
I must say right away that everything below does not belittle node.js in any way, I generally have a negative attitude towards jokes about php / 1c developers, I have quite a positive attitude towards js, especially es6 =)
There are only two types of programming languages: those that people swear at all the time, and those that no one uses.
Answer the question
In order to leave comments, you need to log in
Promise (+ async/await for node 8, which will be LTS, I'll switch to it in a couple of months from node 6), sequelize as ORM. Express as a router.
Since we are talking about all this noodles, maybe someone can explain to me.
I have several actions following each other, and I have to wait until the previous operation is completed before I can do more.
1. Check if the ssh connection is
working 2. Check if the ssh connection to another server is working
3. Run the next step
Function:
backupRun.prototype.checkSSHConnection = async function (serverName) {
var self = this;
var exec = self.bConfig.clientserver[self.eServer]
var client = self.bConfig.clientserver[serverName]
return new Promise((resolve, reject) => {
self.runUnderSSH("hostname", self.sshkey, exec, client)
.then((sshOutput) => {
return resolve(sshOutput);
}, (sshOutputErr) => {
return reject(sshOutputErr)
})
})
};
backupJob.checkSSHConnection(program.exec) //check ssh to exec server
.then((response) => {
logger.debug("SSH test connection to exec " + program.exec + " successfull");
backupJob.checkSSHConnection(program.server) //check ssh connection to backup server
.then((response) => {
logger.debug("SSH test connection to backup server " + program.exec + " successfull");
backupJob.createBackupPrePostCommands('prerun') //create backup server prerun commands
.then((backupPreRun) => {
logger.debug("Create backup prerun commands");
}, (err) => {
logger.error("Error: config array was not generated " + err);
})
})
})
}, (error) => {
logger.error("SSH test connection to backup server " + program.exec + " failed: " + error);
})
}, (error) => {
logger.error("SSH test connection to exec " + program.exec + " failed: " + error);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question