As a simple sample program, I have a node script that constantly connects the server and wants this program to run for a long time.
The program is configured as a ping function that returns a promise object. A promise is allowed or rejected based on whether ping worked or failed.
I want this function to work in a loop, so regardless of whether ping is successful or not, the next ping is then launched after a certain time after the previous request has been resolved.
The problem is not the problem itself, but I am worried about my implementation. I believe that this will lead to a stack overflow in the end.
Here is some code to find out what is going on:
function doPing(host) {
}
function doEvery(ms, callback, callbackArgs) {
setTimeout(function() {
callback.apply(null, callbackArgs)
.always(function() {
doEvery(ms, callback, callbackArgs);
});
}, ms);
}
doEvery(1000, doPing, [host]);
, :
?
, promises?