angular - How to neatly chain promises in Javascript -
how can write function neater, returning resolving in timeout callback best way this? i'm asking because i'm new javascript promises.
getstuff(): promise<any> { let self = this; return new promise(function(resolve, reject) { self.getdata() .then(function(resp) { self.parse(resp); }) .then(function() { settimeout(function() { resolve(); }, 5000); }); }); }
see example below...
getstuff(): promise<any> { let self = this; return new promise(function(resolve, reject) { self.getdata() .then(function(resp) { return self.parse(resp); //return here }) .then(function(resp2) { settimeout(function() { resolve(resp2); }, 5000); }, (err) => reject(err)); }); }
Comments
Post a Comment