My goal is to make a simple JSON parser which runs continuously. As I imagined it - an infinity loop makes a request and stores data in my DB. Simple. But there always were memory leaks. What is the proper way to make things run repeatedly over and over again in Node.js? What is actually memory leak? Why it is happening? I have tried it to do with setInterval, setTimeOut, processNextTick, setImmediate, promises but there is always the same result! I am obviously something missing.
What I get now:
function getItems(callback) {
request({
url: 'http://foo.com',
json:true
}, function (error, response, body) {
if (!error && response.statusCode == 200 && body) {
var total_count = body.total_count;
var body = body.results_html;
...
setTimeout(function() {callback(body}, 1000);
}
});
}
function series(item) {
if(item) {
getItems(function(result) {
console.log(result);
return series(true);
});
} else {
return ;
}
}
series(true);
Aucun commentaire:
Enregistrer un commentaire