I have this nested functions but it only called the first 2 functions and then skipped the others. Add it is too fast to redirect to another page. What I wanted to achieve is this and making sure that every instances finishes its job before proceeding to another instances:
Scenario:
First instance // first called
Sec instance // next called then
Third instance // next called then
Fourth instance // last called
So this is what I did:
function creacteAccount(db_name, contact, email) {
if (!(db_name > "" && contact > "" && email > "")) {
return Promise.reject("One of the parameters is empty");
}
return session.rpc('/custom/createdb', {db_name: db_name})
.then(function () {
console.log("Database created successfully");
return session.rpc('/custom/initdb', {db_name: db_name});
}).then(function () {
console.log("Database initialized successfully");
return session.rpc('/custom/installapps', {db_name: db_name});
}).then(function () {
console.log("Apps installed successfully");
return session.rpc('/custom/createaccount', {
db_name : db_name,
contact_name: contact,
email_from: email
});
}).then(function () {
console.log("User account created successfully");
});
}
creacteAccount(db_name, contact, email).then(function () {
console.log("Successfully creating your account")
}).catch(function (err) {
alert("Could not create account! (" + err + ")");
});
Then this is the error displayed in my console:
> Uncaught TypeError: creacteAccount(...).then(...).catch is not a function