I am using angularJS and trying to creating amazon VPC through aws.sdk.js
Now when I create VPC I have to done various configuration and call below methods in chain
- create vpc
() => vpc_
- create internet gateway
() => igw_
- attach internet gateway
(vpc_, igw_) =>
- create subnet
(vpc_) => subnet_
- create route table
(vpc_) => rtb_
- associate route table
(rtb_, subnet_) =>
- create security group
(vpc_) => sg_
add inbound rule
(sg_) =>
additionally create tags for each generated resources .
as you can see some function parameter depends on previous function and so on. I am using $q services on each AWS method but this is became so large callback hell.
I also capture notifications of each function in back so my input function became like this
functionOne().then(function(res1) {
console.info(res1);
functionTwo(res1.id).then(res2) {
console.info(res2);
......... series of functions within function....
----------------
----------------
.then(res7) { functionEight(res7.id) {
}, function (err) {}, function (notify) {})
.finally(function(){ console.log('Finally done everything'); });
---------------------
---------------------
}, function (err2) {
console.error(err2);
}, function (notify2) {
console.log(nofify2);
});
}, function (err1) {
console.error(err1);
}, function (notify1) {
console.log(nofify1);
});
my function signature is as below
functionX: function() {
var d = $q.defer();
var params = {
//...
};
ec2.anyMethodName(params, function(err, data) {
if (err) {
d.reject(err);
} else {
d.notify('Notifications methods');
d.resolve(data);
}
});
return d.promise;
}
You can see the chaining of methods in my controller here
So my question is
Does Amazon native thenable promise property can be used in angular? if yes then how do we implement notifications?
Is there any sorter way to do that? like error will be captures in last? using
$.all()
but do not not how?If i use
.finally()
on functionOne than it throw error in console .finally is not a function