im currently working on a project that uses a few microservices and one of them must do the same thing over and over again.
The code looks like this:
refresh: function(){
return somePromise
.then(doA)
.then(doB)
.then(doC)
.catch(error)
}
So currently another function calls this "refresh" function with setInterval every second.
The problem is that because of the async nature of these calls in refresh method, some bugs appear.
I changed the code to call the 'refresh' method again recursively in the last '.then' statement and removed the setInterval.
refresh: function(){
return somePromise
.then(doA)
.then(doB)
.then(doC)
.then(refresh)
}
Nowthe bugs appear to be gone and everything works perfectly. My question is: Is this a good practice? Are there any memory problems with calling the "refresh" method recursively in the last '.then' statement?