So I was wondering what is a better way (in terms of stack growth and performance) to recursively call a function at regular intervals? For example, lets say I want to read file
There is no recursion in the following simplified example:
function test()
{
console.trace();
setTimeout(test, 1000);
}
test();
output (note that stack is not growing)
Trace
at test (/private/tmp/rec.js:3:12)
at Object.<anonymous> (/private/tmp/rec.js:7:1)
at Module._compile (module.js:449:26)
at Object..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function._load (module.js:312:12)
at module.js:487:10
at EventEmitter._tickCallback (node.js:238:9)
Trace
at Object.test [as _onTimeout] (/private/tmp/rec.js:3:12)
at Timer.ontimeout (timers.js:101:19)
Trace
at Object.test [as _onTimeout] (/private/tmp/rec.js:3:12)
at Timer.ontimeout (timers.js:101:19)
Trace
at Object.test [as _onTimeout] (/private/tmp/rec.js:3:12)
at Timer.ontimeout (timers.js:101:19)
Trace
at Object.test [as _onTimeout] (/private/tmp/rec.js:3:12)
at Timer.ontimeout (timers.js:101:19)
Trace
at Object.test [as _onTimeout] (/private/tmp/rec.js:3:12)
at Timer.ontimeout (timers.js:101:19)
Trace
at Object.test [as _onTimeout] (/private/tmp/rec.js:3:12)
at Timer.ontimeout (timers.js:101:19)