Petras Petras - 13 days ago 5
Node.js Question

How to repeat part of this JS function forever every 30 seconds?

Okay, so heres the full source of my function. All I want that the part that is surrounded by "////////////" would repeat. New function works too. I could have them both, very confused once I tried to pull the highlighted function into a new one and got loads of errors.

function reWebLogOn(steam, callback) {
steam.webLogOn(function(newCookie){
helper.msg('webLogOn ok');
cookies = newCookie;
offers.setup({
sessionID: currentSessionId,
webCookie: newCookie
}, function(){
if (typeof callback == "function") {
callback();
}
});
var steamcommunityMobileConfirmations = new SteamcommunityMobileConfirmations(
{
steamid: config.steamid,
identity_secret: config.identitySecret,
device_id: device_id,
webCookie: newCookie,
});


///////////////////////////////////////////////////////////////////////////////////////////////////////////


steamcommunityMobileConfirmations.FetchConfirmations((function (err, confirmations)
{
if (err)
{
console.log(err);
return;
}
console.log('steamcommunityMobileConfirmations.FetchConfirmations received ' + confirmations.length + ' confirmations');
if ( ! confirmations.length)
{
return;
}
steamcommunityMobileConfirmations.AcceptConfirmation(confirmations[0], (function (err, result)
{
if (err)
{
console.log(err);
return;
}
console.log('steamcommunityMobileConfirmations.AcceptConfirmation result: ' + result);
}).bind(this));
}).bind(this));

///////////////////////////////////////////////////////////////////////////////////////////////////////////

});
}

Answer

use timer's, an Interval would be handy

setInterval(function() {
    //.. part that should be repleated
}, 30*1000);
Comments